C++ || Sliding Window || easy to understand
Just check the number of zeroes in each window of size equal to the number of 1\'s present in the array.\n\n\nclass Solution {\npublic:\n    int minSwaps(vector
Just check the number of zeroes in each window of size equal to the number of 1\'s present in the array.\n\n```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n        int count=0;\n        for(int i=0;i<nums.size();i++)\n            if(nums[i]==1)\n                count++;\n        int result=0;\n      \n        for(int i=0;i<count;i++)\n        {\n             if(nums[i]==0)\n                 result++;\n        }\n       \n        int ans=result;\n        for(int i=1;i<nums.size();i++)\n        {\n            int j=(i+count-1)%nums.size();\n            if(nums[i-1]==0)\n                result--;\n            if(nums[j]==0)\n                result++;\n            ans=min(ans,result);\n        }\n        return ans;\n    }\n};\n```
['C', 'Sliding Window']