Python 3 || 7 lines, extend , zip  || T/S: 99% / 27%
\nclass Solution:\n    def minSwaps(self, nums: list[int]) -> int:\n\n        n, k = len(nums), sum(nums)\n        mx = tally = sum(nums[:k])\n        nums.exte
```\nclass Solution:\n    def minSwaps(self, nums: list[int]) -> int:\n\n        n, k = len(nums), sum(nums)\n        mx = tally = sum(nums[:k])\n        nums.extend(nums[:k])\n        \n        for num1, num2 in zip(nums[k:], nums):\n            tally+= num1 - num2\n            if tally > mx: mx = tally\n        \n        return k - mx\n```\n[https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/submissions/1341324911/](https://leetcode.com/problems/minimum-swaps-to-group-all-1s-together-ii/submissions/1341324911/)\n\nI could be wrong, but I think that time complexity is *O*(*N*) and space complexity is *O*(1), in which *N* ~ `len(nums).
['Python3']