<p>You are given an integer array, <code>nums</code>, and an integer <code>k</code>. <code>nums</code> comprises of only <code>0</code>&#39;s and <code>1</code>&#39;s. In one move, you can choose two <strong>adjacent</strong> indices and swap their values.</p>

<p>Return <em>the <strong>minimum</strong> number of moves required so that </em><code>nums</code><em> has </em><code>k</code><em> <strong>consecutive</strong> </em><code>1</code><em>&#39;s</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,0,0,1,0,1], k = 2
<strong>Output:</strong> 1
<strong>Explanation:</strong> In 1 move, nums could be [1,0,0,0,<u>1</u>,<u>1</u>] and have 2 consecutive 1&#39;s.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,0,0,0,0,0,1,1], k = 3
<strong>Output:</strong> 5
<strong>Explanation:</strong> In 5 moves, the leftmost 1 can be shifted right until nums = [0,0,0,0,0,<u>1</u>,<u>1</u>,<u>1</u>].
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,1,0,1], k = 2
<strong>Output:</strong> 0
<strong>Explanation:</strong> nums already has 2 consecutive 1&#39;s.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>nums[i]</code> is <code>0</code> or <code>1</code>.</li>
	<li><code>1 &lt;= k &lt;= sum(nums)</code></li>
</ul>

class Solution:
    def minMoves(self, nums: List[int], k: int) -> int:
        if k==1:
            return 0
        n=len(nums)
        ind=[i for i in range(len(nums)) if nums[i]==1]
        pref=[0]*n
        for i in range(n):
            pref[i]+=pref[i-1]+(nums[i]==0)
        win=ind[:k]
        l,hi=0,k-1
        sl,sr=0,0
        ans=float("inf")
        lh=k//2
        rh=k-k//2
        sl=sum([pref[i] for i in win[:k//2]])
        sr=sum([pref[i] for i in win[k//2:]])
        li=deque(win[:k//2])
        ri=deque(win[k//2:])
        win=deque(win)
        while hi<len(ind):
            ans=min(ans,(pref[win[k//2]]*lh)-sl+(sr-(pref[win[k//2]]*rh)))
            l+=1
            hi+=1
            if hi<len(ind):
                x=win.popleft()
                xl=li.popleft()
                xr=ri.popleft()
                sl-=pref[xl]
                sl+=pref[xr]
                li.append(xr)
                ri.append(ind[hi])
                sr-=pref[xr]
                sr+=pref[ind[hi]]
                win.append(ind[hi])

        return ans
26200