C++ || Sliding Window
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\nApproach: let count of 1s be \'k\', so after rearranging, we will be having a window
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n**Approach**: let count of 1s be \'k\', so after rearranging, we will be having a window of size \'k\'\n \n```\nclass Solution {\npublic:\n\n    int minSwaps(vector<int> &a) {\n        int n=a.size();\n        \n        int k=0;\n        for(int i=0;i<n;i++)  k += (a[i]==1);\n        \n        a.insert(a.end(), a.begin(), a.end()); // doubling the size of array as it is circular\n        \n        int ans=n;\n        \n        int i=0, j=0, one=0;\n        while(j<2*n){\n            one += (a[j]==1);\n            \n            if(j-i+1 == k){\n                ans = min(ans,k-one); // k-one will number of swaps required to make all elements of window sized \'k\' as 1\n                one -= (a[i]==1);\n                \n                i++;\n            }\n            j++;\n        }\n        \n        return (ans==n ? 0:ans);\n    }\n};\n```\n\n**Do Upvote If It Helps**
['C++']