C and C++
C solution\n\nchar * maximumBinaryString(char * binary){\n    int n = strlen(binary) ;\n    int firstZeroIdx = -1 ;\n    for(int i = 0; i < n; i++){\n        if
C solution\n```\nchar * maximumBinaryString(char * binary){\n    int n = strlen(binary) ;\n    int firstZeroIdx = -1 ;\n    for(int i = 0; i < n; i++){\n        if(binary[i] == \'1\')\n            continue ;\n        if(firstZeroIdx >= 0){\n            binary[firstZeroIdx] = \'1\' ;\n            binary[firstZeroIdx+1] = \'0\' ;\n            firstZeroIdx++ ;\n            binary[i] = \'1\' ;\n        }\n        else{\n            if(i < n-1 && binary[i+1] == \'0\')\n                binary[i] = \'1\' ;\n            else\n                firstZeroIdx = i ;\n        }\n    }\n    return binary ;\n}\n```\nC++ solution\n```\nclass Solution {\npublic:\n    string maximumBinaryString(string binary) {\n        int n = binary.size() ;\n        int firstZeroIdx = -1 ;\n        for(int i = 0; i < n; i++){\n            if(binary[i] == \'1\')\n                continue ;\n            if(firstZeroIdx >= 0){\n                binary[firstZeroIdx] = \'1\' ;\n                binary[firstZeroIdx+1] = \'0\' ;\n                firstZeroIdx++ ;\n                binary[i] = \'1\' ;\n            }\n            else{\n                if(i < n-1 && binary[i+1] == \'0\')\n                    binary[i] = \'1\' ;\n                else\n                    firstZeroIdx = i ;\n            }\n        }\n        return binary ;\n    }\n};\n```
[]