javascript
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```javascript []
/**
 * @param {string} s
 * @return {number}
 */
var minFlips = function(s) {
    const n = s.length;
    let flips1 = 0; // Starts with '0101...'
    let flips2 = 0; // Starts with '1010...'

    for (let i = 0; i < n; i++) {
        if (i % 2 === 0) {
            if (s[i] === '1') flips1++;
            else flips2++;
        } else {
            if (s[i] === '0') flips1++;
            else flips2++;
        }
    }

    let minFlips = Math.min(flips1, flips2);

    for (let i = 1; i < n; i++) {
        let removedChar = s[i - 1];
        let addedChar = s[(i + n - 1) % n];

        if ((i - 1) % 2 === 0) {
            if (removedChar === '1') flips1--;
            else flips2--;
        } else {
            if (removedChar === '0') flips1--;
            else flips2--;
        }

        if ((i + n - 1) % 2 === 0) {
            if (addedChar === '1') flips1++;
            else flips2++;
        } else {
            if (addedChar === '0') flips1++;
            else flips2++;
        }

        minFlips = Math.min(minFlips, flips1, flips2);
    }
    return minFlips;
};
```
['JavaScript']