Move towards Median
\nclass Solution:\n    def minMoves(self, nums: List[int], k: int) -> int:\n        ones = [i for i in range(len(nums)) if nums[i] == 1]\n        n = len(ones)\
```\nclass Solution:\n    def minMoves(self, nums: List[int], k: int) -> int:\n        ones = [i for i in range(len(nums)) if nums[i] == 1]\n        n = len(ones)\n        p = [0] * (n + 1)\n        for i in range(n):\n            p[i + 1] = p[i] + ones[i]\n        res = float(\'inf\')\n        for i in range(n - k + 1):\n            median = i + k // 2\n            l = median - i + 1\n            lsum = p[i + l] - p[i]\n            r = k - l\n            rsum = p[i + l + r] - p[i + l]\n            sub = l * (l - 1) // 2 + r * (r + 1) // 2\n            res = min(res, ones[median] * l - lsum + rsum - ones[median] * r - sub)\n        return res\n```
['Python']