Python solution w/ comments
py\nclass Solution:\n    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n        A = sorted(stones)\n        n = len(stones)\n        \n        # e
```py\nclass Solution:\n    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n        A = sorted(stones)\n        n = len(stones)\n        \n        # either keep moving the stone at right endpoint to the left interval between A[0] ... A[n - 2]\n        # basically each empty spot can consume 1 move, so total moves = total # of empty spots inside A[0] .. A[n - 2]\n        # A[n - 2] - A[0] + 1 -    2           - (n - 3)\n        # -------------------      -           ---------\n        # interval length     A[0], A[n-2]    stones already inside\n        #\n        # similar idea for keeping moving the stone at left endpoint to the right interval between A[1] ... A[n - 1]\n        # total # of empty spots = A[n - 1] - stone[1] + 1 - 2 - (n - 3)\n        # we take the maximum of these two moves\n        max_moves = max(A[-1] - A[1] + 1 - 2 - (n - 3), A[-2] - A[0] + 1 - 2 - (n - 3))\n        \n        # for min moves, use a sliding window\n        # idea: https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/286886/No-code-just-chinese-explanation\n        # https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/289357/c++-with-picture\n        l, min_moves = 0, n\n        \n        for r in range(n):\n            # in case current window can hold more than n stones, shrink the window\n            while A[r] - A[l] + 1 > n:\n                l += 1\n            \n            # a special case: A[l] ... A[r] currently is consecutive and there is only one stone (endpoint) outside\n            # in this case we oneed 2 move\n            if A[r] - A[l] == r - l and r - l + 1 == n - 1:\n                min_moves = min(min_moves, 2)\n            else:\n                # refer: leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/286886/No-code-just-chinese-explanation/275066\n                min_moves = min(min_moves, n - (r - l + 1))\n        \n        return [min_moves, max_moves]\n                \n```\nHappy Coding~
[]