Watch 10 video solutions for Maximum Binary String After Change, a medium level problem involving String, Greedy. This walkthrough by Ashish Pratap Singh has 1,002,188 views views. Want to try solving it yourself? Practice on FleetCode or read the detailed text solution.
You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:
"00", you can replace it with "10".
"00010" -> "10010""10", you can replace it with "01".
"00010" -> "00001"Return the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.
Example 1:
Input: binary = "000110" Output: "111011" Explanation: A valid transformation sequence can be: "000110" -> "000101" "000101" -> "100101" "100101" -> "110101" "110101" -> "110011" "110011" -> "111011"
Example 2:
Input: binary = "01" Output: "01" Explanation: "01" cannot be transformed any further.
Constraints:
1 <= binary.length <= 105binary consist of '0' and '1'.