Task 1, Maximum Odd Binary
It's the week of the Artemis 2 mission to the moon, and we have a problem about odd numbers. I'd call that a Space Oddity .
Task Description
You are given a binary string that has at least one β1β.
Write a script to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number and return the resulting binary string. The resulting string can have leading zeros.
Example 1: Input: $str = "1011" , Output: "1101"
Example 2: Input: $str = "100" , Output: "001"
Example 3: Input: $str = "111000" , Output: "110001"
Example 4: Input: $str = "0101" , Output: "1001"
Example 5: Input: $str = "1111" , Output: "1111"
Task Cogitation
To be as large as possible, a binary number must have all its 1s in the most-significant bits. To be odd, the least significant bit must be a one.β¦