package leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * https://leetcode.com/problems/minimum-absolute-difference/
 */
public class Problem1200 {
    public List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        Map<Integer, List<List<Integer>>> map = new HashMap<>();
        int min = Integer.MAX_VALUE;
        for (int i = 1; i < arr.length; i++) {
            int diff = arr[i] - arr[i - 1];
            min = Math.min(min, diff);
            if (!map.containsKey(diff)) {
                map.put(diff, new ArrayList<>());
            }
            map.get(diff).add(Arrays.asList(arr[i - 1], arr[i]));
        }
        return map.get(min);
    }

    public static void main(String[] args) {
        Problem1200 prob = new Problem1200();
        System.out.println(prob.minimumAbsDifference(new int[]{4,2,1,3})); // [[1,2],[2,3],[3,4]]
        System.out.println(prob.minimumAbsDifference(new int[]{1,3,6,10,15})); // [[1,3]]
        System.out.println(prob.minimumAbsDifference(new int[]{3,8,-10,23,19,-4,-14,27})); // [[-14,-10],[19,23],[23,27]]
    }
}

@@ -777,415 +777,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1200 prob = new Problem1200();%0A        System.out.println(prob.minimumAbsDifference(new int%5B%5D%7B4,2,1,3%7D)); // %5B%5B1,2%5D,%5B2,3%5D,%5B3,4%5D%5D%0A        System.out.println(prob.minimumAbsDifference(new int%5B%5D%7B1,3,6,10,15%7D)); // %5B%5B1,3%5D%5D%0A        System.out.println(prob.minimumAbsDifference(new int%5B%5D%7B3,8,-10,23,19,-4,-14,27%7D)); // %5B%5B-14,-10%5D,%5B19,23%5D,%5B23,27%5D%5D%0A    %7D
 %0A%7D%0A

Update problem 1200