O(n) -> Sliding window
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\nNote: It can be easily optimised to O(1) by calculating the bits dynamically on the go, inste
# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n**Note**: It can be easily optimised to O(1) by calculating the bits dynamically on the go, instead of storing them initially.\n\n# Code\n```python3 []\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        n = len(s)\n        s2 = s*2\n        target1 = "01" * n\n        target2 = "10" * n\n        diff1 = 0\n        diff2 = 0\n        for i in range(n):\n            if s2[i] != target1[i]:\n                diff1 += 1\n            if s2[i] != target2[i]:\n                diff2 += 1\n        i = 0\n        j = n\n        diff = min(diff1, diff2)\n        while i < n:\n            if s2[j] != target1[j]:\n                diff1 += 1\n            if s2[i] != target1[i]:\n                diff1 -= 1\n            if s2[j] != target2[j]:\n                diff2 += 1\n            if s2[i] != target2[i]:\n                diff2 -= 1\n            diff = min(diff, diff1, diff2)\n            i += 1\n            j += 1\n        return diff       \n        \n```
['Two Pointers', 'String', 'Sliding Window', 'Python3']