15 lines of code in C++ faster than 100.00% Memory Usage: less than 99.04%
\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int k) {\n        int temp =0, mid = k/2, left = 0, right = k, n = 0;\n        for(int i =0; i<
```\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int k) {\n        int temp =0, mid = k/2, left = 0, right = k, n = 0;\n        for(int i =0; i<nums.size(); i++)\n            if(nums[i]==1) nums[n++]=i;\n        for(int ind =0; ind<k; ind++)\n            temp += abs(nums[mid] -nums[ind])-abs(mid-ind);\n        int ans = temp;\n        while(right<n){\n            temp += (nums[right]-nums[(k & 1)?(mid+1):mid]) - (nums[mid]-nums[left]);\n            left++, mid++, right++;\n            ans = ans>temp ? temp : ans;\n        }\n        return ans;\n    }\n};\n```
['Sliding Window']