Python Solution Sliding Window with Explaination
After swaps , the length of the sequence of 1 is equal to the total number of 1. Use sliding window with the size of the total number of 1 to find the interval 
After swaps , the length of the sequence of 1 is equal to the total number of 1. Use sliding window with the size of the total number of 1 to find the interval which has the most number of 1. The number of 0 in this interval will be the minimum swap needed.\n\nk is the number of 1.\ns represent the number of 1 in [i-k + 1: i + 1]\n\n```\nclass Solution:\n    def minSwaps(self, nums: List[int]) -> int:\n        k = sum(nums)\n        if len(nums) ==1:\n            return 0\n        s = collections.defaultdict(int)\n        s[0] = sum(nums[-k + 1:])+ nums[0]\n        for i in range(1, len(nums)):\n            s[i] = s[i-1] - nums[i -1 -k + 1] + nums[i]\n        print(s)\n        return k - max(s.values())
['Sliding Window']