C++ solution(sliding window)
Here we use the concept of sliding window..we count the number of 1\'s in vector and make a window of that size...and we once traverse in the window of that siz
**Here we use the concept of sliding window..we count the number of 1\'s in vector and make a window of that size...and we once traverse in the window of that size and count no of 1\'s in  that window(count)...and assign maxcount as count and noww we simply traverse the complete vector in that window size(k) and decrease the size of count if the last element was 1 and increase the count by one if the new element is 1\nAnd then return (window size(k)-maxcount) **\n\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n\t\n        int count=0,maxcount=0,k=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]==1) k++;\n        }\n        if(k<=1) return 0;\n        for(int i=0;i<k;i++)\n        {\n            if(nums[i]==1)\n                count++;\n        }\n        maxcount=count;\n        for(int i=k;i<nums.size()+k;i++)\n        {\n            if(nums[i-k]==1)count--;\n            if(nums[i%nums.size()]==1)count++;\n            maxcount=max(maxcount,count);\n        }\n        return (k-maxcount);\n    }\n};\n(please do upvote if you like it)
['Sliding Window']