Python O(N) solution
Observation 1. Type-1 operation is just rotation, we can rotate input string as much as we like.\nObservation 2. If the length is even, rotations don\'t help. I
Observation 1. Type-1 operation is just rotation, we can rotate input string as much as we like.\nObservation 2. If the length is even, rotations don\'t help. If the length is odd, rotation is equivalent to flipping the rotated bit.\n\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        N = len(s)\n        d = [0,0]\n        for i,v in enumerate(s):\n            d[(i&1)^(v==\'1\')] += 1\n        if not N&1:\n            return min(d)\n        d1 = [0,0]\n        best = min(d)\n        for j in range(N-1,-1,-1):\n            d[(j&1)^(s[j]==\'1\')] -= 1\n            d1[(j&1)^(s[j]==\'0\')] += 1\n            best = min(best,d[0]+d1[0],d[1]+d1[1])\n        return best\n```
['Python']