[Python] Constant Length Sliding Window + Commented  | TC - O(N)
Code\n\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        N, s = len(s), s + s\n        diff, ans = 0, math.inf\n\n        ## Alternating Strings
# Code\n```\nclass Solution:\n    def minFlips(self, s: str) -> int:\n        N, s = len(s), s + s\n        diff, ans = 0, math.inf\n\n        ## Alternating Strings Can only be of 2 types\n        ## Type1 = 010101010...\n        ## Type2 = 101010101...\n        ## Another thing to notice is that they would always be complementary to each other\n        ## i.e. if 2 swaps are needed to change a string to type1, N-2 swaps would be needed to change to type2 and vice-versa\n        type1 = "".join([str(1*(i%2)) for i in range(2*N)])\n\n        ## For the original-string(window of size N) check the swaps needed\n        for char, a in zip(s[:N], type1[:N]):\n            if char != a: diff += 1    \n        ans = min(ans, diff, N - diff)\n\n        ## This is the best case scenario - i.e. the string is already alternating\n        if ans == 0:\n            return 0\n\n        ## Now simulating a sliding window to incorporate the 1st Operation given in the problem\n        ## i.e. Removing the first character and appending it to the end\n        ## The rest is generic constant length sliding window with constantly checking the leftmost and rightmost(newly added) characters\n        for i in range(1,N):\n            if type1[i-1] != s[i-1]: diff -= 1\n            if type1[i+N-1] != s[i+N-1]: diff += 1\n            ans = min(ans, diff, N - diff)\n\n        return ans\n```
['Sliding Window', 'Python3']