Mid/SeniorGreedyString

Maximum Binary String After Change

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:

  • Operation 1: If the number contains the substring "00", you can replace it with "10".
  • Operation 2: If the number contains the substring "10", you can replace it with "01".

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
Inputbinary = "000110"
Output"111011"
A valid transformation sequence is "000110" -> "000101" -> "100101" -> "110101" -> "110011" -> "111011".
Example 2
Inputbinary = "01"
Output"01"
"01" cannot be transformed any further.

Constraints

  • 1 <= binary.length <= 10^5
  • binary consist of '0' and '1'.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate