O(n) time, O(k) space, 2 deques
Basicaly we split the data structure that stores the number of zeroes between every two consequitive 1\'s in the sliding window into left and right halfs.\n\nTo
Basicaly we split the data structure that stores the number of zeroes between every two consequitive 1\'s in the sliding window into left and right halfs.\n\nTo iterate over the sliding windows of the solution will move the leftmost element of the right deque into the rightmost end of the left deque. Thus having O(1) access time to all necessary statistiques of the number of zeroes at all ends of the halfs of the split sliding window, and can maintain the necessary invariants:\n- total number of moves for current window\n- number of zeroes in he left half of the sliding window\n- number of zeroes in right half of the sliding window\n\nTherer is some gimmickery to handle the case when the ```k =2```  and the right deque is empty, but overall very straightforward solution.\n\n\n```\nfrom collections import deque\nclass Solution:\n    def minMoves(self, nums, k):\n        def countZeros(nums, start):\n            zero_count = 0\n            for i in range(start, len(nums)):\n                if nums[i] == 1:\n                    return (zero_count, i)\n                else:\n                    zero_count += 1\n            return (zero_count, len(nums))\n\n        if k==1:\n            return 0\n\n        lq = deque()\n        rq = deque()\n        size_lq = k//2\n        size_rq = (k-1)//2\n        i = nums.index(1)\n        cur_moves = 0\n        zeros_left = 0 \n        zeros_right = 0\n        while len(lq) < size_lq:\n            cur_zeros, i = countZeros(nums, i+1)\n            cur_moves += (len(lq) + 1) * cur_zeros\n            zeros_left += cur_zeros\n            lq.append(cur_zeros)\n\n        while len(rq) < size_rq:\n            cur_zeros, i = countZeros(nums, i+1)\n            cur_moves += (size_rq-len(rq)) * cur_zeros\n            zeros_right += cur_zeros\n            rq.append(cur_zeros)\n        \n        min_moves = cur_moves\n\n        while i < len(nums): \n            cur_zeros, i = countZeros(nums, i+1)\n            if i == len(nums):\n                break\n            cur_moves -= zeros_left\n            cur_moves += zeros_right\n            cur_moves += cur_zeros\n            if k%2:\n                cur_moves -= rq[0]\n\n\n            zeros_left -= lq.popleft()\n            rq.append(cur_zeros)\n            right_to_left = rq.popleft()\n            zeros_left += right_to_left\n            if len(rq) > 0:\n                zeros_right -= right_to_left\n                zeros_right += cur_zeros\n            lq.append(right_to_left)\n            min_moves = min(min_moves, cur_moves)\n\n        return min_moves\n```
[]