C# Solution - presum + sliding window O(n)
\npublic class Solution {\n    public int MinMoves(int[] nums, int k) {\n        List<int>oneIndex = new List<int>();\n         for (int i = 0; i < nums.Length;
```\npublic class Solution {\n    public int MinMoves(int[] nums, int k) {\n        List<int>oneIndex = new List<int>();\n         for (int i = 0; i < nums.Length; ++i){\n            if (nums[i] == 1){\n                oneIndex.Add(i);\n                }\n             }\n        int result = Int32.MaxValue;\n        List<int>preSum = new List<int>();\n        preSum.Add(0);\n        for (int i = 0; i < oneIndex.Count; ++i) {\n            preSum.Add(preSum[i] + oneIndex[i]);\n            //Console.WriteLine(preSum[i] + oneIndex[i]);\n\t\t\t}\n        for (int i = 0; i <  oneIndex.Count - k + 1; ++i)\n            result = Math.Min(result, preSum[i + k] - preSum[k / 2 + i] - preSum[(k + 1) / 2 + i] + preSum[i]);\n        result -= (k / 2) * ((k + 1) / 2);\n        return (int)result;\n        \n    }\n}\n```
[]