[C++] Well commented code| Explaination | O(n)
We can try all possible rotations, and for each rotation find min flips.\n> This can be done in O(n) by concatenating the string to its own end . Every window w
We can try all possible **rotations**, and for each rotation find **min flips**.\n> This can be done in **O(n)** by concatenating the string to its own **end** . Every window we take in this string where **window size** is original string\'s initial length,  is a rotation of **original** **string**.\n\n**Now comes the part of counting flips:**\nfor a string of size n, we are actually trying to make\n1010101......n\n0101010.....n\nIn the first one we want 1 **at odd places(1 based indexing)** and **0 at evens**, and reverse in second one.\nIf we keep count of all  4 counts and change them during sliding , we can actually find our ans.\nThats it is the logic , Implementations will be clearer from the code and comments.\n\nPlease upvote if it helps :)\n```\nint check(int evens[], int odds[] , int n) {\n\tint o, e;\n\tif (n % 2 == 0)\n\t\to = n / 2, e = n / 2;\n\telse\n\t\te = n / 2, o = n - e;\n\n\tint moves = INT_MAX;\n\t//choose 1 at odds and 0 at evens\n\tmoves = min(moves, max(o - odds[1], 0) + max(e - evens[0], 0));\n\t//choose 1 at evens and 0 at odds\n\tmoves = min(moves, max(e - evens[1], 0) + max(o - odds[0], 0));\n\treturn moves;\n}\n\n\nint minFlips(string s) {\n\tint n = s.length();\n\ts += s;\n\n\tint odds[2] = {0, 0}, evens[2] = {0, 0};\n\n\tint i = 0;\n\t//i am following 1 based indexing everywhere\n\twhile (i < n ) {\n\t\tif ((i + 1) % 2 == 0) {\n\t\t\tevens[s[i] - \'0\']++;\n\t\t} else {\n\t\t\todds[s[i] - \'0\']++;\n\t\t}\n\t\ti++;\n\t}\n\n\tint ans = INT_MAX;\n\tans = min(ans , check(evens, odds, n));\n\tint j = i;\n\ti = 0;\n\n\twhile (j < s.length()) {\n\t\t//shrink from back and reduce odds\n\t\t//since 1 element is removed it will always be odd\n\t\todds[s[i++] - \'0\']--;\n\t\t//after shiting odds become evens and evens become odds\n\t\tswap(evens[0], odds[0]);\n\t\tswap(odds[1], evens[1]);\n\t\t//add the new added character to appropraite position\n\t\t//added characters position depends on the size of window/given string\n\t\tif (n % 2 == 0) evens[s[j] - \'0\']++;\n\t\telse odds[s[j] - \'0\']++;\n\n\t\tans = min(ans , check(evens, odds, n));\n\t\tj++;\n\t}\n\n\treturn ans;\n}\n```
['C', 'Sliding Window', 'C++']