Greedy + Thought Process + Explanation [4 lines]
Intuition\n Describe your first thoughts on how to solve this problem. \n### Rule 1: 00 -> 10\n### Rule 2: 10 -> 01\n\nGiven some zero, and some ones, say, 1111
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n### Rule 1: 00 -> 10\n### Rule 2: 10 -> 01\n\nGiven some zero, and some ones, say, 111110, we can repeatedly apply rule 2 to \'pass it left\', i.e., 11110 -> 11101 -> 11011...\n\nGiven some zeros, we can always reduce them by one each time, whenever two zeroes meet, as per rule 1. For example, 10101 -> 10011 (rule 1) -> 11011 (rule 2). Two zeros can always be forced to meet (through repeated left shifts from rule 2) and then reduced by one/switched for a 1 (from rule 1)\n\nEffectively, all zeros can be forced to meet eventually (example 1) and reduced by 1. Inductively, this means that we can reduce the number of zeros to 1, which is optimal. Each time two zeros meet, the leftmost one shifts right one. Using this logic, the leftmost zero will effectively move right by the total number of zeros - 1 (i.e., excluding the one that needs to move), and everything else becomes a 1.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nFind the leftmost 0. Find the number of zeros. Shift it right by this number, and fill the rest with 1s. In the code, `lmz` is left-most zero, and `z_idx` is the new index of the zero.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$ - build new string\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(1)$$ - ignoring return string, only three variables are used\n\n# Code\n```\nclass Solution:\n    def maximumBinaryString(self, binary: str) -> str:\n        lmz, zeros = binary.find(\'0\'), binary.count(\'0\')\n        if lmz == -1:\n            return binary\n\n        z_idx, N = lmz + zeros - 1, len(binary)\n        return "1" * (z_idx) + "0" + "1" * (N - 1 - z_idx)\n```
['Python3']