C++ Code
class Solution {\npublic:\n    vector numMovesStonesII(vector& stones) {\n        sort(stones.begin(), stones.end());\n\n        int N = stones.size(), low = N;
class Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        sort(stones.begin(), stones.end());\n\n        int N = stones.size(), low = N;\n        for (int i = 0, j = 0; j < N; ++j) {\n            while (stones[j] - stones[i] + 1 > N) {\n                ++i;\n            }\n            if (N - (j - i + 1) == 1 && N - (stones[j] - stones[i] + 1) == 1) {\n                low = min(low, 2);\n            } else {\n                low = min(low, N - (j - i + 1));\n            }\n        }\n\n        int high = 1 + max((stones[N - 1] - stones[1] + 1) - N,  // Move to right most\n                           (stones[N - 2] - stones[0] + 1) - N); // Move to left most\n        return {low, high};\n    }\n};
['C++']