Using sliding window technique, O(1) space, with comments, Simple & Easy, [C++]
Implementation\n\nUsing sliding window technique\nTime Complexity = O(N), Space Complexity = O(1)\n\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nu
Implementation\n\n**Using sliding window technique\nTime Complexity = O(N), Space Complexity = O(1)**\n```\nclass Solution {\npublic:\n    int minSwaps(vector<int>& nums) {\n        int countOne = 0, n = nums.size();\n        \n        // count the total number of 1\'s present into array\n        for(int itr = 0; itr < n; itr++){\n            if(nums[itr]) countOne++;\n        }\n        \n        // if no 1 is present then simply return 0\n        if(countOne == 0) return 0;\n        \n        // taking the window size of the total 1\'s count\n        int windowSize = countOne;\n        int currCountOne = 0;        \n        \n        // counting the number of 1\'s present into the starting window size from 0\n        for(int itr = 0; itr < countOne; itr++){\n            if(nums[itr]) currCountOne++;\n        }\n        \n        // putting into the res, bcz res will hold the maximum number of 1\'s present into the current window size\n        int res = currCountOne;\n        for(int itr = 1; itr < n; itr++){\n            \n            // if leading element is 1 then decrement it by 1, bcz now it\'s not in a current window\n            if(nums[itr-1]) currCountOne--;\n            \n            // if trailing element is 1 then increment it by 1, bcz now it\'s in a current window\n            if(nums[(itr + windowSize - 1) % n]) currCountOne++;\n            \n            // storing the maximum count of 1\'s in a current window\n            res = max(res, currCountOne);\n        }        \n        \n        // return total number of 1\'s in a array - maximum count of 1\'s in a current window\n        return windowSize - res;\n    }\n};\n```\nIf you find any issue in understanding the solution then comment below, will try to help you.\nIf you found my solution useful.\nSo **please do upvote and encourage me** to document all leetcode problems\uD83D\uDE03\nHappy Coding :)
['C', 'Sliding Window']