a few solutions
Use a sliding window of length n to find the minimal mismatch count between case a and b as the best answer:\n\n case a: target starts with 0, ie. 010101..., so
Use a sliding window of length `n` to find the minimal mismatch count between case `a` and `b` as the `best` answer:\n\n* case `a`: target starts with `0`, ie. `010101...`, so every even digit is expected to be `0` and every odd digit is expected to be `1`\n* case `b`: target starts with `1`, ie. `101010...`, so every even digit is expected to be `1` and every odd digit is expected to be `0`\n\t* ie. `b` is the opposite of `a`\n\nWe can append `s` onto itself to consider the wrap-around cases.\n\n---\n\n*Javascript*\n```\nlet minFlips = (s, cnt_a = 0, cnt_b = 0, best = Infinity) => {\n    let ord = c => c.charCodeAt(0) - \'0\'.charCodeAt(0);\n    let n = s.length;\n    s = `${s}${s}`;\n    for (let i = 0; i < s.length; ++i) {\n        let x = ord(s[i]);\n        let a = i & 1, b = a ^ 1;\n        if (x != a) ++cnt_a;\n        if (x != b) ++cnt_b;\n        if (n <= i) {\n            let y = ord(s[i - n]);\n            a = (i - n) & 1, b = a ^ 1;\n            if (y != a) --cnt_a;\n            if (y != b) --cnt_b;\n        }\n        if (n - 1 <= i)\n            best = Math.min(best, cnt_a, cnt_b);\n    }\n    return best;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def minFlips(self, s: str, a = 0, b = 1, cnt_a = 0, cnt_b = 0, best = float(\'inf\')) -> int:\n        n = len(s)\n        s = f\'{s}{s}\'\n        for i in range(len(s)):\n            a = i & 1\n            b = a ^ 1\n            x = int(s[i])\n            if x != a: cnt_a += 1\n            if x != b: cnt_b += 1\n            if n <= i:\n                a = (i - n) & 1\n                b = a ^ 1\n                y = int(s[i - n])\n                if y != a: cnt_a -= 1\n                if y != b: cnt_b -= 1\n            if n - 1 <= i:\n                best = min(best, cnt_a, cnt_b)\n        return best\n```
[]