Maximum Odd Binary Number - Problem
You are given a binary string s that contains at least one '1'.
You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.
Return a string representing the maximum odd binary number that can be created from the given combination.
Note that the resulting string can have leading zeros.
Input & Output
Example 1 — Basic Case
$
Input:
s = "010"
›
Output:
"001"
💡 Note:
We have one '1' and two '0s. To maximize and keep odd: place 0 '1's at front (since 1-1=0), two '0's in middle, and one '1' at end → "001"
Example 2 — Multiple 1s
$
Input:
s = "101"
›
Output:
"101"
💡 Note:
We have two '1's and one '0'. Place 1 '1' at front, one '0' in middle, one '1' at end → "101". This is already optimal.
Example 3 — Many 1s
$
Input:
s = "1111"
›
Output:
"1111"
💡 Note:
All bits are '1'. Place 3 '1's at front, no '0's in middle, one '1' at end → "1111". Already maximum odd number.
Constraints
- 1 ≤ s.length ≤ 100
- s consists only of '0' and '1'
- s contains at least one '1'
Visualization
Tap to expand
Understanding the Visualization
1
Input
Binary string with mixed 1s and 0s
2
Process
Rearrange to maximize while keeping odd
3
Output
Maximum possible odd binary number
Key Takeaway
🎯 Key Insight: Place all 1s at front for maximum value, except keep one 1 at end to ensure odd
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code