C++  solution | Sliding window for minimum moves
First, sort the given stones array.\n1. To find minimum moves, we approach the problem by checking each window which has a size not greater than stones.size(). 
First, **sort** the given stones array.\n1. To find **minimum** moves, we approach the problem by checking each window which has a size not greater than **stones.size()**. The intitution is that in a window which has size less than or equal to the number of stones, we can always get the unoccupied spaces and accordingly put the other stones inside and outside that window to make them consecutive. We just have to get that window in which we can do so in least number of moves.\n2. To find **maximum** moves, we just have to make the stones jump only to their **nearest** unoccupied space in a move and keep doing this until all the stones are consecutive.\n```\nclass Solution {\npublic:\n    vector<int> numMovesStonesII(vector<int>& stones) {\n        int n = stones.size();\n        vector<int> result;\n        \n\t\t// sorting the stones array\n        sort(stones.begin(), stones.end());\n        \n\t\t// window size, stones count in a window\n        int i = 0, j = 0, wsize, scount, minMoves = INT_MAX;\n        \n        while (j < n) {\n            wsize = stones[j] - stones[i] + 1;\n            scount = j - i + 1;\n            \n\t\t\t// if window size becomes greater than number of stones\n            if (wsize > n) {\n                i++;\n                continue;\n            }\n            \n\t\t\t/* To handle some corner cases\n\t\t\t   Example - _ _ 3 4 5 6 _ _ 10\n\t\t\t   Here, putting, stone at 10th position, next to stone at 6th position is an invalid move.\n\t\t\t*/\n            if (wsize == n - 1 && scount == n - 1)\n                minMoves = min(minMoves, 2);\n            \n            else minMoves = min(minMoves, n - scount);\n                                    \n            j++;\n        }\n        \n        result.push_back(minMoves);\n        \n        int maxMoves;\n\t\t\n\t\t// consecutive stones at the beginning or consecutive stones at the end or both\n        if (stones[1] == stones[0] + 1 || stones[n - 1] == stones[n - 2] + 1)\n            maxMoves = stones[n - 1] - stones[0] + 1 - n;\n        \n\t\t// non-consecutive stones at both the beginning and the end\n        else \n            maxMoves = max(((stones[n - 1] - stones[1]) - (n - 1) + 1), ((stones[n - 2] - stones[0]) - (n - 1) + 1));\n        \n        result.push_back(maxMoves);\n        \n        return result;\n    }\n};
['C', 'Sliding Window']