package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/moving-stones-until-consecutive-ii/
 */
public class Problem1040 {
    public int[] numMovesStonesII(int[] stones) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1040 prob = new Problem1040();
        System.out.println(Arrays.toString(prob.numMovesStonesII(new int[]{7, 4, 9}))); // [1,2]
        System.out.println(Arrays.toString(prob.numMovesStonesII(new int[]{6, 5, 4, 3, 10}))); // [2,3]
        System.out.println(Arrays.toString(prob.numMovesStonesII(new int[]{100, 101, 104, 102, 103}))); // [0,0]
        System.out.println(Arrays.toString(prob.numMovesStonesII(new int[]{1, 2, 5}))); // [2,2]
        System.out.println(Arrays.toString(prob.numMovesStonesII(new int[]{1, 3, 5, 7, 10}))); // [2,4]
    }
}

@@ -204,35 +204,380 @@
     
-// TODO%0A        return null
+Arrays.sort(stones);%0A        int max = Math.max(stones%5B1%5D - stones%5B0%5D, stones%5Bstones.length - 1%5D - stones%5Bstones.length - 2%5D) - 1;%0A        for (int i = 1; i %3C stones.length - 2; i++) %7B%0A            max += stones%5Bi + 1%5D - stones%5Bi%5D - 1;%0A        %7D%0A        if (max == 0) %7B%0A            return new int%5B%5D%7B0, max%7D;%0A        %7D%0A        int min = 0;%0A        return new int%5B%5D%7Bmin, max%7D
 ;%0A  
@@ -1079,24 +1079,24 @@
 ); // %5B2,2%5D%0A
-
         Syst
@@ -1187,16 +1187,984 @@
 / %5B2,4%5D%0A
+        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 12%7D))); // %5B2,5%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 13%7D))); // %5B2,6%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 13, 18%7D))); // %5B3,10%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 13, 14%7D))); // %5B3,9%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 13, 18, 23%7D))); // %5B4,14%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 13, 18, 23, 24%7D))); // %5B4,17%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 5, 8, 13, 19, 23, 24%7D))); // %5B4,17%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B1, 50, 100, 200%7D))); // %5B3,148%5D%0A        System.out.println(Arrays.toString(prob.numMovesStonesII(new int%5B%5D%7B4, 8, 10, 12, 14, 20%7D))); // %5B3,8%5D%0A
     %7D%0A%7D%0A

Update problem 1040