Rearrange the bits of a binary string to form the largest possible odd binary number.
Given a binary string s, rearrange its characters to form the numerically largest possible binary number that is odd.
A binary number is odd only if its last bit is 1. You may reorder the characters in any way, but you must use all characters exactly once.
Return one such maximum odd binary string.
s.s contains only characters '0' and '1'.s is '1' so that an odd result is possible.s.1 <= s.lengths[i] ∈ {'0','1'}'1'.Example 1
Input
s = "0101"
Output
"1001"
Explanation
The string has two 1s and two 0s. To make the largest odd number, place one 1 at the end and the other 1 as far left as possible: 1001.
Example 2
Input
s = "111"
Output
"111"
Explanation
The string is already the largest possible odd binary number.
Example 3
Input
s = "1010"
Output
"1001"
Explanation
Using all bits, the maximum odd arrangement is 1001.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.