Sliding Window
We move the fixed-size sliding window, wrapping it around the array. The lenght of the sliding window is the number of ones.\n\nWe track and return the minimum 
We move the fixed-size sliding window, wrapping it around the array. The lenght of the sliding window is the number of `ones`.\n\nWe track and return the minimum number of "holes" in our sliding window. Each of those "holes" needs to be swapped.\n\n**Java**\n```java\npublic int minSwaps(int[] nums) {\n    int ones = Arrays.stream(nums).sum(), n = nums.length, res = nums.length;\n    for (int i = 0, j = 0, cnt = 0; i < n; ++i) {\n        while (j - i < ones)\n            cnt += nums[j++ % n];\n        res = Math.min(res, ones - cnt);\n        cnt -= nums[i];\n    }\n    return res;\n}\n```\n**C++**\n```cpp\nint minSwaps(vector<int>& nums) {\n    int ones = count(begin(nums), end(nums), 1), n = nums.size(), res = n;\n    for (int i = 0, j = 0, cnt = 0; i < n; ++i) {\n        while (j - i < ones)\n            cnt += nums[j++ % n];\n        res = min(res, ones - cnt);\n        cnt -= nums[i];\n    }\n    return res;\n}\n```
['C', 'Java']