[Java/Python 3] Sliding Window O(n) code w/ brief explanation and analysis.
Denote as winWidth the total number of 1\'s in the input array, then the goal of swaps is to get a window of size winWidth full of 1\'s. Therefore, we can maint
Denote as `winWidth` the total number of `1`\'s in the input array, then the goal of swaps is to get a window of size `winWidth` full of `1`\'s. Therefore, we can maintain a sliding window of size `winWidth` to find the maximum `1`\'s inside, and accordingly the minimum number of `0`\'s inside the sliding window is the solution.\n\n```java\n    public int minSwaps(int[] nums) {\n        int winWidth = 0;\n        for (int n : nums) {\n            winWidth += n;\n        }\n        int mx = 0;\n        for (int lo = -1, hi = 0, onesInWin = 0, n = nums.length; hi < 2 * n; ++hi) {\n            onesInWin += nums[hi % n];\n            if (hi - lo > winWidth) {\n                onesInWin -= nums[++lo % n];\n            }\n            mx = Math.max(mx, onesInWin);\n        }\n        return winWidth - mx;\n    }\n```\n```python\n    def minSwaps(self, nums: List[int]) -> int:\n        win_width = sum(nums)\n        lo, mx, ones_in_win = -1, 0, 0\n        n = len(nums)\n        for hi in range(2 * n):\n            ones_in_win += nums[hi % n]\n            if hi - lo > win_width:\n                lo += 1\n                ones_in_win -= nums[lo % n]\n            mx = max(mx, ones_in_win)    \n        return win_width - mx\n```\n\n**Analysis:**\n\nTime: `O(n)`, space: `O(1)`, where `n = nums.length`.
['Java', 'Python3']