Python3 solution O(NlogN) with explaination
\nclass Solution:\n    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n        stones.sort()\n        minM = float(\'inf\')\n        for i in range
```\nclass Solution:\n    def numMovesStonesII(self, stones: List[int]) -> List[int]:\n        stones.sort()\n        minM = float(\'inf\')\n        for i in range(1,len(stones)-1):\n            loc = bisect.bisect_left(stones, stones[i]+len(stones)-1, lo=0, hi=len(stones)-1)\n            if stones[loc] == stones[i]+len(stones)-1:\n                minM = min(minM,len(stones)-(loc-i)-1)\n            else:\n                minM = min(minM,len(stones)-loc+i)\n        if stones[-1]-stones[0]+1 == len(stones):\n            minM = 0\n        maxM = max(stones[-2]-stones[0]-len(stones)+2,stones[-1]-stones[1]-len(stones)+2)\n        return [minM,maxM]\n```\nFor max moves, after first move, we can move the end one as "outside" as possible, thus this is easy to compute.\nFor mim moves, we examine how the final state is like, (consective from ith position), we just need to check how many vacancies there are in this range.
[]