Easy Python - 2 lines - Beats 100%
Solution Walkthrough\n\nLet us carefully examine the operations - \n\nOperation 1: If the number contains the substring "00", you can replace it with "10".\nFor
# Solution Walkthrough\n\nLet us carefully examine the operations - \n\n***Operation 1: If the number contains the substring "00", you can replace it with "10".\nFor example, "00010" -> "10010"\nOperation 2: If the number contains the substring "10", you can replace it with "01".\nFor example, "00010" -> "00001"***\n\nNow observing our end goal - Greatest binary number using the above operations. So, we need to have the maximum number of ones in the start and try to move zeros, if any at last(ideally) as we can. But it happens that it is not always possible to have the zeros at last.\nNow trying to visualize the solution - \n\n\t1. Do not try to touch the ones in the beginning as they are at their optimal place. Let us analyze this thing once - Eg - "110101" => "110011" => "111011" (Hence only sequence from where first 0 occurs need to be considered while maximizing)\n\t2. Remember rule 1 and try to group together all the zeros together (in the start) and the ones after that together. Group all the zeros before the remaining ones. We can just do this by using Operation 2. Eg - "01100101" => "01100011" => "01010011" => "01001011" => "01000111" => "00100111" => "00010111" => "00001111"\n\t3. Finally, applying Operation 1 from the first occuring 0. Eg - "00001111" => "10001111" => "11001111" => "11101111" (Answer)\n\n**Note - We will always have a single 0 (at max) in the answer.**\n\n```\nclass Solution:\n    \'\'\'\n    Runtime: 44 ms, faster than 100.00% of Python3 online submissions for Maximum Binary String After Change.\n\tMemory Usage: 15.6 MB, less than 59.78% of Python3 online submissions for Maximum Binary String After Change.\n    \'\'\'\n\t\n\t\'\'\'\n\t1. Variable Description -> first_zero => first occurence index of 0, num_zeros => Total number of zeros in the input binary string.\n\t2. If there are no zeros, directly return the binary string (Already in the desired form).\n\t3. Put all the ones(1) till first 0 occurence as it is and covert remaining num_zeros - 1 zeros to 1.\n\t3. Put the last remaining 0 now as we can\'t do anything about it.\n\t4. Now put the remaining 1s => (total length of binary string) - (count of zeros) - (count of ones at the beginning)\n\t\'\'\'\n    def maximumBinaryString(self, binary: str) -> str:\n        first_zero, num_zeros = binary.find(\'0\'), binary.count(\'0\')\n        return (\'1\' * ( first_zero + num_zeros - 1 )) + \'0\' + (\'1\' * (len(binary) - num_zeros - first_zero)) if zeros else binary\n```
['Python3']