Convert to Base Minus Two
In base -2 the digit positions are worth 1, -2, 4, -8, 16, and so on, and every integer has exactly one representation using only the digits 0 and 1 with no leading zeros. Return the base -2 form of n as a string (zero is "0").
Example 1
n 2
returns "110"
"110": 4 - 2 + 0 = 2.
Example 2
n 3
returns "111"
"111": 4 - 2 + 1 = 3.
Constraints
0 <= n <= 1000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Count Numbers With Unique DigitsMedium
- Count PrimesMedium
- Day of the WeekMedium
- Fast PowerMedium
- Friday the 13th CountMedium
- Last Digit of a PowerMedium
- Last Person StandingMedium
- Minimum Moves to Equal ElementsMedium