Ctrl K

Largest Odd Bit Shuffle

Easy
You are given a string bits of zeros and ones that contains at least one 1. Rearrange its characters to form the largest binary number that is odd. Return the resulting string. Its length stays the same, and leading zeros are allowed.
Example 1
bits="0110" → '1001'

One 1 must go last, or the number is even. The remaining 1, 0, 0 give the largest prefix 100, so the answer is 1001.

Example 2
bits="100" → '001'

There is only one 1, and it moves to the end: 001. Leading zeros are fine.

Example 3
bits="11" → '11'
Constraints
  • 1 ≤ len(bits) ≤ 100
  • bits consists of the characters 0 and 1
  • bits contains at least one 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Biggest Odd Chunk EasyYour Own Keypad Layout EasyRound Prices to a Total MediumCross Swaps of x and y MediumLucky Ticket With Blanks Medium
loading Python…
Input
bits="0110"
Expected
'1001'

Run checks the first 3 tests in your browser. Submit checks all 81 tests on the server, hidden ones included.