[C++] cakewalk
Intuition\nI took some sample test cases and tried to find some pattern, I got a thought that:\n- Try to move all 0\'s using 10->01 transformation and then appl
# Intuition\nI took some sample test cases and tried to find some pattern, I got a thought that:\n- Try to move all **0\'s** using **10->01** transformation and then apply \n**00->10** transformation , if there are **n** zeros where **n>=2** , maximum of **n-1** 1\'s can be there in resultant string\n\n# Approach\nI took some sample test cases and tried to find some pattern, I got a thought that:\n- If there is a single **\'0\'** or all **\'1\'s** the best solution is to leave string as it as , as in case of single **\'0\'** if we try to move it leftwards it will remove higher set bits.\n- Also if there are terminal **0\'s** leftwards collecting all of them at the starting will help in setting higher bits.\n- If there are none of terminal **0\'s** leftwards, try to find first **\'0\'** and shift all other zeros besides it\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    void createResultString(int count0, int count1, string &result){\n      for(int i=1 ;i<=count0-1;i++)\n        result+="1";\n\n        result+="0";\n\n        for(int i=1; i<=count1; i++)\n        result+="1";\n    }\n    string maximumBinaryString(string binary) {\n        int count0 = 0;\n        int count1 = 0;\n        string result = "";\n        for(int i=0; i<binary.size(); i++){\n            if(binary[i] == \'0\')\n            count0++;\n            else\n            count1++;\n        }\n      \n\n        if(count0 == 0 || count0 == 1)\n        return binary;\n         \n        int it = 0;\n        while(true){\n            if(binary[it] == \'1\'){\n            result+="1";\n            count1--;\n            }\n            else\n            break;\n            it++;\n        }\n        createResultString(count0, count1, result);\n        return result;\n    }\n};\n```
['C++']