Sliding window
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nCreate  2x ideal alternate string. Ie 0101 or 1010. \n2x the input string
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nCreate  2x ideal alternate string. Ie 0101 or 1010. \n2x the input string.\nUse the sliding window approach. For window of original length s : Maintin/count diff from two alternate string.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$ Due to Alternate String\n\n# Code\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        s = s + s\n        size = len(s)\n        alt_string_1 = "01"*(size//2)\n        alt_string_2 = "10"*(size//2)\n        \n        res = size\n        left = 0\n        diff_count_1 = 0\n        diff_count_2 = 0\n\n        for right, char in enumerate(s):\n            if char != alt_string_1[right]:\n                diff_count_1 += 1\n            if char != alt_string_2[right]:\n                diff_count_2 += 1\n            \n            # if window is original size of s\n            if (right-left+1) == size/2:\n                res = min(diff_count_1, diff_count_2, res)\n\n                if s[left] != alt_string_1[left]:\n                    diff_count_1 -= 1\n                if s[left] != alt_string_2[left]:\n                    diff_count_2 -= 1\n                \n                left += 1\n        \n        return res\n            \n\n            \n\n\n```
['Python3']