Skip to content

Practice Convert to Base -2

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1017
LeetCode Problem

Convert to Base -2

Problem Statement

Given an integer n, return a binary string representing its representation in base -2. Note that the returned string should not have leading zeros unless the string is "0".

Source: Convert to Base -2 on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2
Output
"110"
Explanation

(-2)^2 + (-2)^1 = 2.

# Example 2

Input
n = 3
Output
"111"
Explanation

(-2)^2 + (-2)^1 + (-2)^0 = 3.

# Example 3

Input
n = 4
Output
"100"
Explanation

(-2)^2 = 4.

Constraints

0 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Convert to Base -2.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.