Concise Explanation with Solution (C++)
Concept\n1. To maximize the string the first most digit alone matters the most, i.e. even if we convert 0111 to 1000 , number would get bigger.\n\n1. "10" can b
# Concept\n1. To maximize the string the first most digit alone matters the most, i.e. even if we convert 0111 to 1000 , number would get bigger.\n\n1. "10" can be converted to "01" which basically means any number can be converted to format "000..111..." (where total number of zeroes and ones are preserved )\n\n1. "00" can be converted to "10" which means a string with only zeroes "0000" can be converted to ones with last char remaining zero "1110"\n# Solution\n1. Leave the starting consecutive "1"s as it is \n\n1. Remaining string can be converted to the format "000..111.." by simply counting number of "1"s and "0"s \n\n1. All zeros except the rightmost will change to one in the converted part of string. \n\n# C++ Code\n```\nclass Solution {\npublic:\n    \nstring maximumBinaryString(string binary) {\n        \n        // o is the count of ones , z is the count of zeroes\n        int o=0,z=0;\n    \n        // res is the resulting string\n        string res="";\n        \n        for(int i=0;i<binary.size();i++){\n            \n            if(binary[i]==\'1\') \n                if(z) o++;\n                else res+=\'1\';\n            \n            else \n                z++;\n        }\n    \n        if(z){\n            while(z--)\n                res += \'1\';\n\n            res[res.size()-1]=\'0\';\n        }\n        while(o--)\n            res += \'1\';\n        \n        return res;\n        \n    }\n};\n```
[]