[C++] Clean Sliding Window Solution
Solution: We can account for the circular array constraint of the question by simply doubling the size of the array. The question then becomes, find the closest
**Solution:** We can account for the circular array constraint of the question by simply doubling the size of the array. The question then becomes, find the closest sliding window match with k (where k = the number of ones in nums) ones. The number of swaps needed is the number of mismatches (1 != 0) in the current window. The answer is the minimum number of swaps needed for any window. \n```\nint minSwaps(vector<int>& nums) {\n        int N = nums.size(), ones = 0, mismatches = 0;\n        for (int i = 0; i < N; i++) nums.push_back(nums[i]);\n        for (int i = 0; i < N; i++) ones += nums[i] == 1;\n        for (int i = 0; i < ones; i++) mismatches += nums[i] == 0;\n        int ans = mismatches;\n        for (int i = ones; i < 2 * N; i++) {\n            if (nums[i] == 0) mismatches++;\n            if (nums[i - ones] == 0) mismatches--;\n            ans = min(ans, mismatches);\n        }\n        return ans;\n}\n```
['Sliding Window']