[JavaScript] 2 pointer Time: O(n) Space: O(1)
javascript\n/*\n\nstartZeroNumFlips:  number of flips if string were to start at i and start with 0\nstartOneNumFlips:  number of flips if string were to start 
```javascript\n/*\n\nstartZeroNumFlips:  number of flips if string were to start at i and start with 0\nstartOneNumFlips:  number of flips if string were to start at i and start with 1\n\n*/\n var minFlips = function(s) {\n    // value to hold starting with zero\n    let startZeroNumFlips = 0;\n    for (let i = 0; i < s.length; i++) {\n        if (i % 2) {\n            if (s[i] === \'0\') startZeroNumFlips++;\n        } else {\n            if (s[i] === \'1\') startZeroNumFlips++;\n        }\n    }\n    let startOneNumFlips = s.length - startZeroNumFlips;\n\n    let minimumFlips = Math.min(startZeroNumFlips, startOneNumFlips);\n    const isEvenLength = s.length % 2 === 0;\n\n    for (let i = 1; i < s.length; i++) {\n        \n        // check the previous char to see which\n        // value to decrement\n        if (s[i - 1] === \'1\') {\n            startZeroNumFlips--;    \n        } else {\n            startOneNumFlips--;\n        }\n\n        // swap the 2 variables because we shifted the index by 1\n        [startOneNumFlips, startZeroNumFlips] = [startZeroNumFlips, startOneNumFlips];\n\n        // add corresponding number of flips\n        if (isEvenLength) {\n            if (s[i - 1] === \'1\') {\n                startOneNumFlips++;\n            } else {\n                startZeroNumFlips++;\n            }\n        } else {\n            if (s[i - 1] === \'1\') {\n                startZeroNumFlips++;\n            } else {\n                startOneNumFlips++;\n            }\n        }\n\n        // calculate the number of flips\n        minimumFlips = Math.min(startZeroNumFlips, startOneNumFlips, minimumFlips);\n    }\n    return minimumFlips;\n};\n```
['Two Pointers', 'JavaScript']