C++ | Easy and best Soln | Faster
\n\tclass Solution {\n\tpublic:\n    int minSwaps(vector<int>& nums) {\n        int sum = accumulate(nums.begin(), nums.end(), 0), m = 0, ma = 0;\n        nums.
```\n\tclass Solution {\n\tpublic:\n    int minSwaps(vector<int>& nums) {\n        int sum = accumulate(nums.begin(), nums.end(), 0), m = 0, ma = 0;\n        nums.insert(nums.end(), nums.begin(), nums.end());\n        for(int i=0; i<sum; i++) {\n            if(nums[i]==1) ma+=1;\n        }\n        int j = sum;\n        m = max(m, ma);\n        for(int i=1; i<=nums.size()-sum; i++) {\n            if(nums[i-1]==1) ma--;\n            if(nums[j]==1) ma++;\n            j++;\n            m = max(m, ma);\n        }\n        return sum-m;\n    }\n};\n```
[]