'Coding has over 700 languages', '67% of programming jobs aren’t in the technology industry', 'Coding is behind almost everything that is powered by electricity'
Topics

Convert to base '-2'

Moderate
0/80
Average time to solve is 30m
profile
Contributed by
2 upvotes
Asked in company
Infosys

Problem statement

Given a number 'N', you need to find a string having “1” or “0” that is equivalent to the value of integer 'N' in base “-2”.

Note:
The resulting string must not have leading zeros unless the string is “0”.
For Example:
If 'N' = 4, then its value in base ‘-2’ will be “100” as 0*(-2)^0 +0*(-2)^1 + 1*(-2)^2 = 4.
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 50
0 <= N <= 10^9

Time limit: 1 sec
Sample Input 1:
2
6
2
Sample Output 1:
11010
110
Explanation Of Sample Input 1:
Test Case 1: Value of  string “11010” in base ‘10’ = 0*(-2)^0 +1*(-2)^1 + 0*(-2)^2 +1*(-2)^3 +1*(-2)^4 = 0 + (-2) + 0 + (-8) + (16) = 6.

Test Case 2: Value of  string “110” in base ‘10’ = 0*(-2)^0 +1*(-2)^1 + 1*(-2)^2 = 0 + (-2) + 4 = 2.
Sample Input 2:
2
5
8
Sample Output 2:
101
11000
Full screen
Console