C++ Solution | Sliding Window | Easy to Understand
\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n\n        int n = nums.size();\n        int target = 0;\n\n        for(int i=0;i<n;i++) {\n 
```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n\n        int n = nums.size();\n        int target = 0;\n\n        for(int i=0;i<n;i++) {\n            if(nums[i]==1) {\n                target++;\n            }\n        }\n\n        if(target == 0) {\n            return 0;\n        }\n\n        for(int i=0;i<n;i++) {\n            nums.push_back(nums[i]);\n        }\n\n        n*=2;\n\n        int ans = INT_MAX;\n\n        int i=0,j=0;\n        int cnt = 0;\n        while(j<n) {\n            if(j-i+1<target) {\n                if(nums[j]==1) {\n                    cnt++;\n                }\n                j++;\n            } else if(j-i+1==target) {\n                if(nums[j]==1) {\n                    cnt++;\n                }\n\n                ans = min(ans, target-cnt);\n\n                if(nums[i]==1) {\n                    cnt--;\n                }\n                i++;\n                j++;\n            }\n        }\n        return ans;\n\n    }\n};\n```
['Two Pointers', 'Sliding Window', 'C++']