O(N) Simple Traversal Approach
\nclass Solution {\npublic:\n    int minFlips(string t) {\n        int i,n=t.length(),cnt=0;\n        int p[n][2],s[n][2];\n        if(t[0]==\'1\'){\n          
```\nclass Solution {\npublic:\n    int minFlips(string t) {\n        int i,n=t.length(),cnt=0;\n        int p[n][2],s[n][2];\n        if(t[0]==\'1\'){\n            p[0][0]=1;\n            p[0][1]=0;\n        }\n        else{\n            p[0][0]=0;\n            p[0][1]=1;\n        }\n        \n        for(i=1;i<n;i++){\n            if(t[i]==\'1\'){\n                p[i][1]=p[i-1][0];\n                p[i][0]=1+p[i-1][1];\n            }\n            else{\n                p[i][0]=p[i-1][1];\n                p[i][1]=1+p[i-1][0];\n            }\n        }\n        \n        if(t[n-1]==\'1\'){\n            s[n-1][0]=1;\n            s[n-1][1]=0;\n        }\n        else{\n            s[n-1][1]=1;\n            s[n-1][0]=0;\n        }\n        \n        for(i=n-2;i>=0;i--){\n            if(t[i]==\'1\'){\n                s[i][1]=s[i+1][0];\n                s[i][0]=1+s[i+1][1];\n            }\n            else{\n                s[i][0]=s[i+1][1];\n                s[i][1]=1+s[i+1][0];\n            }\n        }\n        \n        int ans=min(s[0][0],s[0][1]);\n        \n        for(i=1;i<n;i++){\n            int part1=s[i][1],part2=s[i][0];\n            if((n-i)%2){\n                if(i%2){\n                    ans=min({ans,part1+p[i-1][0]});\n                    ans=min({ans,part2+p[i-1][1]});\n                }\n                else{\n                    ans=min({ans,part1+p[i-1][1]});\n                    ans=min({ans,part2+p[i-1][0]});\n                }\n            }\n            else{\n                if(i&1){\n                    ans=min({ans,part1+p[i-1][1]});\n                    ans=min({ans,part2+p[i-1][0]});\n                }\n                else{\n                    ans=min({ans,part1+p[i-1][0]});\n                    ans=min({ans,part2+p[i-1][1]});\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n```
['Greedy', 'C', 'C++']