[C++] Well commented | Easy to understand | simple comparison
\nclass Solution {\npublic:\n    int minFlips(string s) {\n        int n = s.size();\n        if (n < 2)\n            return 0;\n        string S = s+s;\n      
```\nclass Solution {\npublic:\n    int minFlips(string s) {\n        int n = s.size();\n        if (n < 2)\n            return 0;\n        string S = s+s;\n        bool zero = false;\n\t\t// why 2*n -> because char can be moved from starting to ending as well, \n\t\t// so we need to check for all possible string rotations\n\t\tvector<char> target1(2*n), target2(2*n);\n\t\t\n\t\t// why 2 targets -> target string can either be of the form 010101 or 101010, \n\t\t// so need to check for both variations\n        for (int i=0; i<2*n; i++) {\n            if (zero) {\n                target1[i] = \'0\';\n                target2[i] = \'1\';\n            } else {\n                target2[i] = \'0\';\n                target1[i] = \'1\';\n            }\n            zero = !zero;\n        }\n\n\t\t// check flips required to convert without doing any rotation\n        int a = 0, b = 0;\n        for (int j=0; j<n; j++) {\n            if (target1[j] != S[j])\n                a++;\n            if (target2[j] != S[j])\n                b++;\n        }\n        int ans = min(a,b);\n\t\t// sliding window part\n        // checking each rotation one by one to minimize the answer\n        for (int i=0; i<n; i++) {\n            // removing the first element from the window\n            // so need to update a & b so that they dont account\n            // for the first element\n            if (target1[i] != S[i])\n                a--;\n            if (target2[i] != S[i])\n                b--;\n            // adding a new element towards the end of the window\n            // so need to recompute a & b based on this\n            if (target1[i+n] != S[i+n])\n                a++;\n            if (target2[i+n] != S[i+n])\n                b++;\n            ans = min(ans, min(a, b));\n        }\n        return ans;\n    }\n};\n```
[]