Simple O(N) java solution
Idea is after the operations mentioned on any given valid input string, there can be at max one zero, reasoning is as follows.\n1) When we see 00, naturally we 
Idea is after the operations mentioned on any given valid input string, there can be at max one zero, reasoning is as follows.\n1) When we see 00, naturally we want to replace it with 10 which gives overall higher value\n2) When we see 10, we want to replace it with 01, only if there is a previous 0 which when combined with this replacement gives higher value. \nFor example 110011110 -> 110011101 -> .... after some replacements 110001111. Now we apply final transformatin of replacing each pair of 0s repeatdly with 10.  111001111 -> 111101111 which is overall high value.\nIf you observe closely, we can get all 0s at one place and then replace all 0s except the last one with 1. In the above example, we got all 3 zeroes together and then replace all zeroes except the last zero with 1. This is equivalen to replacing each 0 pair repeateldy with 10. For example 000 -> 100 -> 110 which is replcing first two 0s with 1\n\nNow the next question is where(at what position in input string) do we keep this bunch of 0s together before applying final transformation? \nAnswer would be to keep the zeores together as left as possible so that when we start reaplce each 0 pair with 10, it gives overall higher value. But the left most zero cannot go any left. Moving the leftmost 0 any left doesn\'t give max value. See with above example. In the above left most 0 didn\'t move any further left before applying final transformation. So we group all 0s together starting from leftmost 0.\n\nOverall solution would be to find the first position of 0 from left and count of all 0s. From left position of 0z replace all zeroes with 1 except the last 0.\n\n```\npublic String maximumBinaryString(String binary) {\n        char[] bs = binary.toCharArray();\n        int zcount = 0, pos = -1;\n        for(int i = bs.length - 1; i >= 0; i--){\n            if(bs[i] == \'0\') {\n                bs[i] = \'1\';\n                zcount++;\n                pos = i;\n            }\n            \n        }\n        if(pos >= 0)\n            bs[pos + zcount - 1] = \'0\';\n        return new String(bs);\n    }\n```
[]