Python solution: try to explain more extensively
First thing first, this problem is ridiculous to be used for interviews. The given example 2 is actually an edge case....\n\n\nclass Solution:\n    # This probl
First thing first, this problem is ridiculous to be used for interviews. The given example 2 is actually an edge case....\n\n```\nclass Solution:\n    # This problem is separated into two parts: the max and the min\n    # They use totally different strategies\n    # Max is a little easier: it involves moving all the stones step by step from left to right or right to left\n    # For example: [1,100,102,105,200]\n    # It depends on whether we first move 1 to 101, then 102 to 103, 101 to 104... etc.\n    # Or the other way round, 200 to 104, 105 to 103, 104 to 101, etc.\n    # The max move is max(stones[-1]-stones[1]-1-(n-3), stones[-2]-stones[0]-1-(n-3)) \n    # Getting the min move is more tricky. Because the final result will be a window of size n, the best strategy is it started with a stone position and in the n-size subwindow after it, it contains the most stones possible\n    # For example as in the case [1,100,102,105,200], min move will be\n    # move 1 to 101, move 200 to 104, move 105 to 103\n    # The appropriate technique is to use sliding window. we first set start and try to extend end, and for each end, we ensure stones[end] - stones[start] + 1 <= n\n    # Then for each valid sliding window, we calculate the number of free slots in the window: n - (end - start + 1)\n    # There is a special case: stones = [3,4,5,6,10]\n    # We see that what start = 0, end = 3, the only free slot in the window is at the ends. The proper move is move 3 to position 8 and 10 to position 7. 2 moves\n    \n    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n        stones.sort()\n        n = len(stones)\n        maxmoves = max(stones[-1]-stones[1], stones[-2]-stones[0]) - n + 2\n        start, minmoves = 0, maxmoves\n        for end in range(n):\n            while stones[end] - stones[start] >= n:\n                start += 1\n            if end-start+1 == n-1 and stones[end]-stones[start]+1== n-1:\n                minmoves = min(minmoves, 2)\n            else:\n                minmoves = min(minmoves, n - (end-start+1))\n            #print(start, end, minmoves)\n        return [minmoves, maxmoves]\n```
[]