C++ || Easy to understand
https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones/discuss/987607/O(n)-explanation-with-picture\nTaking reference from above solution, 
https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones/discuss/987607/O(n)-explanation-with-picture\nTaking reference from above solution, C++ code:\n```\nclass Solution {\npublic:\n    int solveOdd(vector<int>&a, int k, vector<long long>&pref){\n        int n=a.size();\n        long long res=INT_MAX;\n        for(int l=0,r=k-1; r<n ; l++,r++){\n            int mid=(l+r)/2;\n            int radius=mid-l;\n            \n            long long right=pref[r]-pref[mid];\n            long long left=(mid==0 ? 0: pref[mid-1])-(l==0 ? 0: pref[l-1]);\n            long long minus=(radius+1)*radius;\n            \n            res=min(res,right-left-minus);\n        }\n        return res;\n    }\n    \n    int solveEven(vector<int>&a, int k, vector<long long>&pref){\n        int n=a.size();\n        long long res=INT_MAX;\n        for(int l=0,r=k-1; r<n ; l++,r++){\n            int mid=(l+r)/2;\n            int radius=mid-l;\n            \n            long long right=pref[r]-pref[mid];\n            long long left=(mid==0 ? 0: pref[mid-1])-(l==0 ? 0: pref[l-1]);\n            long long minus=(radius+1)*radius + (radius+1) + a[mid];\n            \n            res=min(res,right-left-minus);\n        }\n        return res;\n    }\n    \n    int minMoves(vector<int>& nums, int k) {\n        int n=nums.size();\n        vector<int>a;\n        for(int i=0;i<n;i++){\n            if(nums[i]==1)\n                a.push_back(i);\n        }\n        vector<long long>pref(a.size(),0);\n        pref[0]=a[0];\n        for(int i=1;i<a.size();i++){\n            pref[i]=pref[i-1]+a[i];\n        }\n        int ans=0;\n        if(k%2==0)\n            ans=solveEven(a,k,pref);\n        else\n            ans=solveOdd(a,k,pref);\n        return ans;\n    }\n};\n```\n\n
['C']