2 min read Python solution || Beginner friendly
Intuition\n Describe your first thoughts on how to solve this problem. \nWe will solve this problem using a sliding window approach.\n\n# Approach\n Describe yo
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe will solve this problem using a sliding window approach.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSince the question describes a circular array, we create a new array doubling the original array.\n```\n arr = nums + nums\n```\nNow we will create a window of size of total number of ones.\n```\nl = 0\nr = total_ones - 1\n```\nAt each step,move the window one step forwards, and subtract the size of window from the length of window.\n```\nwhile r < len(arr)-1:\n            sm -= arr[l]\n            sm += arr[r+1]\n            l += 1\n            r += 1\n```\nAnd finally,at each step take the minimum and return it. \n\nTake a look at the code and you will understand.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n0(2n) == 0(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n0(2n) == 0(N)\n\n# Code\n```\nclass Solution:\n    def minSwaps(self, nums: List[int]) -> int:\n        total_ones = sum(nums)\n        arr = nums + nums\n        ans = float(\'inf\')\n        l = 0\n        r = total_ones - 1\n        sm = sum(arr[l:r+1])\n        ans = min(ans,r-l+1-sm)\n        while r < len(arr)-1:\n            sm -= arr[l]\n            sm += arr[r+1]\n            l += 1\n            r += 1\n            ans = min(ans,r-l+1-sm)\n        return ans\n\n        \n```
['Python3']