(C++) 1040. Moving Stones Until Consecutive II
\n\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        sort(begin(stones), end(stones)); \n        int n = size(stones)
\n```\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        sort(begin(stones), end(stones)); \n        int n = size(stones), ii = 0, low = INT_MAX, high = max(stones[n-2] - stones[0], stones[n-1] - stones[1]) - (n - 2); \n        \n        for (int i = 0; i < n; ++i) {\n            while (stones[i] - stones[ii] >= n) ++ii; \n            if (i - ii + 1 == n - 1 && stones[i] - stones[ii] == n - 2) low = min(low, 2); \n            else low = min(low, n - (i - ii + 1)); \n        }\n        return {low, high}; \n    }\n};\n```
['C']