C++ O(n) solution
\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int k) {\n        int n=nums.size();\n        long long  radius=(k-1)/2;\n        vector<int> o
```\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int k) {\n        int n=nums.size();\n        long long  radius=(k-1)/2;\n        vector<int> onesind;\n        \n        for(int i=0;i<n;i++)\n            if(nums[i])\n                onesind.push_back(i);\n        \n        int m=onesind.size();\n        long long presum[m+1];\n        presum[0]=0;\n        for(int i=0;i<m;i++)\n            presum[i+1]=presum[i]+onesind[i];\n        \n        long long int mini=INT_MAX;\n        \n        if(k%2)\n        {\n            for(int i=0;i<m-k+1;i++)\n            {\n                long long blue=presum[i+radius]-presum[i];\n                long long red=presum[i+2*radius+1]-presum[i+radius+1];\n                cout<<red<<" "<<blue;\n                mini=min(mini,red-blue-radius*(radius+1));\n            }\n        }\n        else\n        {\n            for(int i=0;i<m-k+1;i++)\n            {\n                long long int blue=presum[i+radius]-presum[i];\n                long long int red=presum[i+2*radius+2]-presum[radius+1+i];\n                cout<<red<<" "<<blue;\n                mini=min(mini,red-blue-onesind[i+radius]-radius*(radius+1)-(radius+1));\n            }\n        }\n        return mini;\n    }\n};`\n```
[]