C++ || SOLUTION
\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int k) {\n        vector<int>Ones;\n        // Take All one\'s indexies\n        for(int i=0;i<
```\nclass Solution {\npublic:\n    int minMoves(vector<int>& nums, int k) {\n        vector<int>Ones;\n        // Take All one\'s indexies\n        for(int i=0;i<nums.size();i++)\n            if(nums[i])\n                Ones.push_back(i);\n        \n        int i=0;\n        int j=0;\n        int ans=INT_MAX;\n        int left_part;\n        int right_part;\n        int left;\n        int right;\n        \n        \n        // Caculate For No of Swaps\n        if(k%2)\n        {   left=k/2;\n            right=k/2;\n            left_part=((k/2)*(k/2+1))/2;\n            right_part=left_part;\n        }\n        else\n        {\n            int a=k/2;\n            left=a-1;\n            right=a;\n            left_part=((a-1)*(a))/2;\n            right_part=((a)*(a+1))/2;\n        }\n        \n        \n        int median=(k-1)/2;\n        int sum=0;\n        int prev_median=(k-1)/2;\n        int shift_value;\n        \n        \n        // create a window of size \'k\'\n        while(j-i+1<k)\n        {\n            // Do Pre-Calculation\n            sum+=abs(Ones[j]-Ones[i+median]);\n            \n            j++;   \n        }\n        \n        \n        // Apply Fix size sliding window with median concept\n        while(j<Ones.size())\n        {\n            shift_value=abs(Ones[median+i]-Ones[prev_median]);\n            shift_value=shift_value*left-(shift_value*(right));\n            \n               // Do Pre-Calculation\n            sum+=abs(Ones[j]-Ones[i+median])+shift_value;\n            \n            // Store result\n            ans=min(ans,sum-left_part-right_part);\n            \n            // Remove Calculation for i\n            sum-=abs(Ones[i]-Ones[i+median]);\n            prev_median=i+median;\n            \n            // Slide the window with maintaining the size of window\n            i++;\n            j++;\n        }\n        \n        \n        return ans;\n    }\n};\n\nTime Complexity: O(2*n)\nSpace Complexity: O(n)\n```\n\n***please correct me if done something wrong, especially time and space complexity.***\n\n***PLEASE UPVOTE IF YOU FIND IT A LITTLE BIT HELFPFUL, MEANS A LOT ;)***\n
['Binary Search', 'Greedy', 'C', 'Sliding Window']