Simple cpp solution using sliding window with explanation. O(N) TC
\nclass Solution {\npublic:\n    //Function that finds differences between given string and string that starts with 01 and 10 and adds given increment.\n    voi
```\nclass Solution {\npublic:\n    //Function that finds differences between given string and string that starts with 01 and 10 and adds given increment.\n    void updateDifference(string &s, int i, int &diffStartWithZero, int &diffStartWithOne, int inc)\n    {\n        //If we are at even index, we should have a 0 here => if string start with 0, else 1 if string start with 1.\n        //Add increment to respective variables if this condition doesn\'t match\n        if(i % 2 == 0)\n        {\n            if(s[i] != \'0\')\n                diffStartWithZero += inc;\n            if(s[i] != \'1\')\n                diffStartWithOne += inc;\n        }\n        //Do the same for odd index\n        else\n        {\n            if(s[i] != \'1\')\n                diffStartWithZero += inc;\n            if(s[i] != \'0\')\n                diffStartWithOne += inc;\n        }\n    }\n    \n    int minFlips(string s) \n    {\n        //Add the string to itself\n        s += s;\n        int len = s.size() / 2, diffStartWithZero = 0, diffStartWithOne = 0, res = INT_MAX;\n        \n        //iterate through the string and do sliding window approach. Window size should be len = s.size()\n        for(int i = 0; i < s.size(); i++)\n        {\n            updateDifference(s, i, diffStartWithZero, diffStartWithOne, 1);\n            \n            //If we have exceeded window of size len, then we need to subtract previous diff if present\n            if(i >= len)\n                updateDifference(s, i-len, diffStartWithZero, diffStartWithOne, -1);\n            \n            //If we have our window size, update res.\n            if(i >= len-1)\n                res = min(res, min(diffStartWithZero, diffStartWithOne));\n        }\n        return res;\n    }\n};\n```
[]