FunctionRacerProblemsRace

Convert to Base Minus Two

MediumMathPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems