C++ | SLIDING WINDOW | 0-1 COUNT
PLEASE UPVOTE IF U LIKE MY SOLUTION\n\n\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n        int n=nums.size();\n        int co=0,minn=n+1
**PLEASE UPVOTE IF U LIKE MY SOLUTION**\n\n```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n        int n=nums.size();\n        int co=0,minn=n+1;\n        for(auto &x:nums)\n        {if(x==1)co++;}\n        int cz=n-co;\n        int coo=0,czz=0;\n        for(int i=0;i<co;i++)\n        {\n            if(nums[i]==1)coo++;\n        }\n        for(int i=0;i<=n-co;i++)\n        {\n           if(i!=0)\n           {\n               if(nums[i-1]==1)coo--;\n               if(nums[i+co-1]==1)coo++;\n           }\n            minn=min(minn,co-coo);\n        }\n        for(int i=0;i<cz;i++)\n        {\n            if(nums[i]==0)czz++;\n        }\n        for(int i=0;i<=n-cz;i++)\n        {\n           if(i!=0)\n           {\n               if(nums[i-1]==0)czz--;\n               if(nums[i+cz-1]==0)czz++;\n           }\n            minn=min(minn,cz-czz);\n        }\n        return minn;\n    }\n};\n```
[]