c++(24ms 100%) iterative, two pass only odd case
Runtime: 24 ms, faster than 100.00% of C++ online submissions for Minimum Number of Flips to Make the Binary String Alternating.\nMemory Usage: 11.3 MB, less th
Runtime: 24 ms, faster than 100.00% of C++ online submissions for Minimum Number of Flips to Make the Binary String Alternating.\nMemory Usage: 11.3 MB, less than 100.00% of C++ online submissions for Minimum Number of Flips to Make the Binary String Alternating.\n**General idea : for cases with even length after counting 1 and 0 : answer = min(even1 + odd0 ,even0 + odd1). But for odd cases of length we will rotate our string (we only fetch first character and embed it in end of string and recalculate . As we have even1, odd0 ,even0, odd1 we only chainge it according to current character)**\n**I tried to find out math solution for odd cases but I dont see any strict dependance . =(**\n```\nclass Solution {\npublic:\n  int minFlips(string s) {\n    int odd1 = 0, odd0 = 0, even1 = 0, even0 = 0, answer, n = s.size();\n    \n    for(int i = 0; i < n; i += 2)\n      s[i] == \'1\' ? even1++ : even0++;   //count 1 and 0 in even places    \n    \n    for(int i = 1; i < n; i += 2)        //count 1 and 0 in odd places \n      s[i] == \'1\' ? odd1++ : odd0++;\n    \n    answer = min(even1 + odd0 ,even0 + odd1);     //if n is even\n    \n    if(n-- % 2 == 1){                             //if n is odd\n      for(int i = 0; i != n; i++){\n        swap(even1,odd1), swap(even0,odd0);\n        if(s[i] == \'0\') odd0--, even0++;\n        else odd1--, even1++;\n        answer = min(answer, min(even0 + odd1 ,even1 + odd0));\n      }\n    }\n    return answer;    \n  }\n};\n```
['C', 'C++']