Use Interval to Get Max Moves
I failed to figure out the min moves... The following is an intuitive solution for max moves.\n1. Sort and get the intervals.\n2. Check the first and last inter
I failed to figure out the min moves... The following is an intuitive solution for max moves.\n1. Sort and get the intervals.\n2. Check the first and last interval, if either is `0`, we are able to reduce every non-zero interval to zero at every smallest move (`1`). Thus, the number of moves is the sum of intervals.\n3. If both first and last intervals are not `0`, we need to drop the smaller one with 1 move, put the stone into the larger one and stick to the outer edge. Then the problem becomes Step 2 above. Node the larger one is reduced by 1, but is done with 1 move, so we can simplify it as: drop smaller one, then sum up the remaining intervals.\n\n```java\nclass Solution {\n    public int[] numMovesStonesII(int[] stones) {\n        Arrays.sort(stones);\n        \n        List<Integer> intervals = new ArrayList<Integer>();\n        for (int i = 1; i <stones.length; i++) {\n            int interval = stones[i] - stones[i-1] - 1;\n            intervals.add(interval);\n        }\n        int maxMove = getMaxMove(new ArrayList<Integer>(intervals));\n        ...\n    }\n\n    private int getMaxMove(List<Integer> intervals) {\n        if (intervals.get(0) != 0 && intervals.get(intervals.size() - 1) != 0) {\n            if (intervals.get(0) > intervals.get(intervals.size() - 1)) {\n                intervals.remove(intervals.size() - 1);\n            } else {\n                intervals.remove(0);\n            }\n        }\n        int count = 0;\n        for (int interval : intervals) {\n            count += interval;\n        }\n        return count;\n    }\n}\n```
[]