[C++]  Prefix + Suffix  - Clean & Easy solution | O(N)
even[i]: cost of turning string [0, i] to binary starting with 0 (pattern: 0 1 0 1 0 ...) - Type-2 operation\n- odd[i]: cost of turning string [0,  i] to binary
- `even[i]`: cost of turning string `[0, i]` to binary starting with 0 (pattern: `0 1 0 1 0 ...`) - Type-2 operation\n- `odd[i]`: cost of turning string `[0,  i]` to binary starting with 1 (pattern: `1 0 1 0 1 ..`.) - Type-2 operation\n\n```\nclass Solution {\npublic:\n    \n    int minFlips(string s) {\n        int n = s.length();\n        int v[n];\n \n        for(int i = 0; i < n; i++) {\n            v[i] = (s[i] - \'0\');\n        }\n \n        int even[n], odd[n];\n\n        even[0] = (v[0] == 0 ? 0 : 1); // start with even 010101\n        odd[0] = (v[0] == 0 ? 1 : 0); // start with odd 101010\n \n        for(int i = 1; i < n; i++) {\n            if (i % 2 == 0) { // even\n                even[i] = even[i-1] + (v[i] == 0 ? 0 : 1);\n                odd[i] = odd[i-1] + (v[i] == 1 ? 0 : 1);\n            } else {\n                even[i] = even[i-1] + (v[i] == 1 ? 0 : 1);\n                odd[i] = odd[i-1] + (v[i] == 0 ? 0 : 1);\n            }\n        }\n \n        int res = min(odd[n - 1], even[n - 1]); // no Type-1 operation\n \n        // states\n        // even[] -> e o e o e -> 1 shift -> o e o e e -> odd[n-1] - odd[i] + even[i] \n        // odd[] -> o e o e o -> 1 shift -> e o e o o -> even[n-1] - even[i] + odd[i]\n        \n        if (n % 2 != 0) {\n            for(int i = 0; i < n; i++) {\n                res = min(res, odd[n-1] - odd[i] + even[i]); \n                res = min(res, even[n-1] - even[i] + odd[i]);\n            }\n        }\n \n        return res;\n    }\n};\n```
[]