easy sliding window using binary search
\nFor the max step just skip the first gap or last gap. detail https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/289357/c%2B%2B-with-pict
\nFor the max step just skip the first gap or last gap. detail https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/289357/c%2B%2B-with-picture\nFor the min step, just do a sliding window and try to move everyone inside the window. result is, window with minimum movement. (one edge case)\n\n\n````\nclass Solution {\n   public:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        int n = stones.size();\n        int minMove = numeric_limits<int>::max();\n        sort(stones.begin(), stones.end());\n        int gap = stones[n - 1] - stones[0] - n + 1;\n\n        // if there is gap in only one side then minimum move is min(2, gap size)\n        if (stones[n - 1] - stones[n - 2] - 1 == gap || stones[1] - stones[0] - 1 == gap) {\n            // 3,4,5,6,_,_,_,_,_,_13 --> 4,5,6,_,3,_,_,_,_,13 --> 4,5,6,13,3\n            minMove = min(2, gap);\n        } else {\n            // we do a simple sliding window with helo of binary search\n            for (int i = 0; i < n; i++) {\n                int inside = upper_bound(stones.begin() + i, stones.end(), stones[i] + n - 1) - stones.begin() - i;\n                minMove = min(minMove, n - inside);\n            }\n        }\n        return {minMove, max(stones[n - 2] - stones[0] - n + 2, stones[n - 1] - stones[1] - n + 2)};\n    }\n};\n````
[]