C++ Code With Easy Explanation
```\nclass Solution {\npublic:\n    vector numMovesStonesII(vector& A) {\n       int n = A.size();  //number of stones\n        \n       sort(A.begin(), A.end()
```\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& A) {\n       int n = A.size();  //number of stones\n        \n       sort(A.begin(), A.end());\n       \n       //To find max_moves:\n       //move either starting endstone, or end endstone : this consumes one Move\n       //after this we calculate the number of free spaces now available, and we will now go through all these \n       //spaces one by one. \n       //Number of spaces available after moving first stone : A[n-1] - A[1] + 1,\n       //Number of spaces available after moving last stone : A[n-2] - A[0] + 1\n       // + 1, for the initial move we made \n       int max_moves = max(A[n-1] - A[1] -n + 1, A[n-2] -  A[0] - n + 1) + 1;\n        \n       //To find min_moves we\'ll use Sliding Window approach:\n       //We will consider a sliding a window of size <=n, which has maximum number of stones init.\n       //minimum_moves will be then equal to n - number of stones already in max_sliding window\n       //Corner case : sliding window size : n-1 and number of stones : n-1,\n       //then minimum number of moves will be atleast 2,consider cases :  {1,2,3,4,10} --> 2 , {1,2,3,4,6} --> 1\n       //\n       //window_size = A[end] - A[start] + 1,  stone_count = start - end + 1\n       int start = 0, end = 0, min_moves = n; \n       while(end < n) {\n           int window_size = A[end] - A[start] + 1;\n           int stone_count = end - start + 1;\n           \n           if(window_size > n) {\n               start++;\n               continue;\n           }\n           \n           if(window_size == n-1 and stone_count == n-1) {\n               min_moves = min(min_moves, 2);\n           }\n           else\n               min_moves = min(min_moves, n - stone_count);\n           \n           end++;\n       }\n        return {min_moves, max_moves};\n    }\n};
[]