Python sliding window approach O(N)
For minimum number of moves, the final arrangement will be of the form [a, a+1, a+2, ... a+L-1] for L stones for some \'a\'. \nThe possible values of \'a\' are 
For minimum number of moves, the final arrangement will be of the form [a, a+1, a+2, ... a+L-1] for L stones for some \'a\'. \nThe possible values of \'a\' are all the stone positions in the given input array.\nFor each possible \'a\' check how many positions (from a to a+L-1) already have stones. We need to fill in the missing remaining positions. Thus if there are K missing positions we need K moves to fill them. Compute K for each value of \'a\' and take their minimum.\n\nFor maximum it is just the sum of the gaps between each stone. But if we take the 1st stone then we cannot count the gaps betwwen 1st and 2nd stone. Similarly if we take the last stone then we cannot count the gaps between last and 2nd last stone. Thus we need to take the maximum of these two cases.\n\n```\nclass Solution(object):\n    def get_min_moves(self, stones):\n        min_cnts = float("Inf")\n        \n        start, end = 0, 1\n        cnts = 1\n        while end < len(stones):\n            if stones[end] < stones[start]+len(stones):\n                cnts += 1\n                end += 1\n            else:\n                rem = len(stones)-cnts\n                if (rem == 1 and stones[end-1] ==  stones[start]+len(stones)-1) or rem != 1:\n                    min_cnts = min(min_cnts, rem)\n                    \n                start += 1\n                cnts -= 1\n                \n        rem = len(stones)-cnts\n        \n        if (rem == 1 and stones[end-1] ==  stones[start]+len(stones)-1) or rem != 1:\n            min_cnts = min(min_cnts, rem)\n                \n        return min_cnts\n    \n    \n    def get_max_moves(self, stones):\n        return max(sum([stones[i]-stones[i-1]-1 for i in range(2, len(stones))]), \n                   sum([stones[i+1]-stones[i]-1 for i in range(len(stones)-3, -1, -1)]))\n    \n    \n    def numMovesStonesII(self, stones):\n        stones = sorted(stones)\n        \n        a = self.get_min_moves(stones)\n        b = self.get_max_moves(stones)\n        \n        return [a, b]
[]