Sliding Window Easy , C++ Beats 90% ✅✅
Approach\n Describe your approach to solving the problem. \nwhat do you think about Window Size.......???\n\nWindow Size = No. of 1 in the given array\nNow try 
# Approach\n<!-- Describe your approach to solving the problem. -->\nwhat do you think about Window Size.......???\n\n**Window Size = No. of 1 in the given array**\nNow try to find out the window size subarray that contains maximum 1.\n\n**Note:-to Handle the circular array problem append the array itself.**\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& arr) {\n        int n =  arr.size(),cnt0= 0,cnt1 = 0,ans = INT_MAX;\n        for(int i = 0;i<n;i++)\n        {\n          if(arr[i]) cnt1++;\n          arr.push_back(arr[i]);   \n        }\n        \n        for(int i = 0;i<cnt1;i++)\n        if(!arr[i]) cnt0++;\n\n        ans = min(ans,cnt0);\n        for(int i = cnt1;i<arr.size();i++)\n        {\n            if(!arr[i]) cnt0++;\n            if(!arr[i-cnt1]) cnt0--;\n\n            ans = min(ans,cnt0);\n        }\n        return ans;  \n    }\n};\n```\n![upvote.jpg](https://assets.leetcode.com/users/images/6dee5915-9c70-4947-8ff7-493fcd9cce2b_1687765982.5258768.jpeg)\n
['Sliding Window', 'C++']