-2 the only digits are 0 and 1, and digit number i (counting from the right, starting at zero) is worth (-2)^i: 1, -2, 4, -8, 16, and so on. For example, the string "110" means 4 − 2 = 2.
Given a non-negative integer n, return its base -2 representation as a string without leading zeros. For n = 0 the answer is "0".n=6 → '11010'
(-2)⁴ + (-2)³ + (-2)¹ = 16 − 8 − 2 = 6, hence "11010".
n=0 → '0'
Zero is written as the single digit "0".
n=7 → '11011'
n=6
'11010'
Run checks the first 3 tests in your browser. Submit checks all 64 tests on the server, hidden ones included.