c++ | easy | fast
\n\n# Code\n\nclass Solution {\npublic:\n       vector<int> numMovesStonesII(vector<int>& A) {\n        sort(A.begin(), A.end());\n        int i = 0, n = A.size
\n\n# Code\n```\nclass Solution {\npublic:\n       vector<int> numMovesStonesII(vector<int>& A) {\n        sort(A.begin(), A.end());\n        int i = 0, n = A.size(), low = n;\n        int high = max(A[n - 1] - n + 2 - A[1], A[n - 2] - A[0] - n + 2);\n        for (int j = 0; j < n; ++j) {\n            while (A[j] - A[i] >= n) ++i;\n            if (j - i + 1 == n - 1 && A[j] - A[i] == n - 2)\n                low = min(low, 2);\n            else\n                low = min(low, n - (j - i + 1));\n        }\n        return {low, high};\n    }\n};\n```
['C++']