[Python] 8-liners with sliding window
With every window contains exactly k ones, the optimal approach is to move every 1\'s to the  position of the median. It can easily be proven by count inversion
* With every window contains exactly `k` ones, the optimal approach is to move every 1\'s to the  position of the median. It can easily be proven by count inversions method)\n* let `x=(k+1)>>1` (i.e half the size of k rounded up), the cost of making such a move is `(x+index[x-1]) * (k%2) + diff - x*x` where `diff` is the diffirent between the sum of indexes between the right and left half. (just Math, it\'s your job to prove it)\n* Every time we slide the window, the diff is increased by the poped element at the beginning of the window minus two times of the new median\n```python\ndef minMoves(self, nums: List[int], k: int) -> int:\n\tnums = [i for i,x in enumerate(nums) if x]\n\tres, diff, x = 1e10, 0, k+1>>1\n\tfor j,i in enumerate(nums):\n\t\tdiff += -i if j < x else i\n\t\tif j >= k -1:\n\t\t\tres = min(res, (x + nums[j-k+x]) * (k%2) + diff - x * x)\n\t\t\tdiff += nums[j-k+1] - 2 * (nums[j-k+x+(k>1)])\n\treturn res\n```
[]