FastPrepInteger to Binary Representation
Problems/Integer to Binary Representation

Integer to Binary Representation

The Walt Disney Company logoThe Walt Disney Company● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The author reports a live technical phone task on HackerRank: convert an integer to binary and pass prepared tests. The report does not define signs, width or built-in policy. This practice uses signed 32-bit inputs, 32-bit two's-complement negatives and unpadded nonnegative strings with zero as 0. About 75% of the reported task scope is represented, as an editorial estimate rather than original-code similarity. The source employment cohort is unavailable; FULLTIME is an operational practice default, not a reported fact.

Convert the signed 32-bit integer n into a binary string using only 0 and 1.

For this exercise, use the conventional 32-bit two's-complement representation for negative inputs. For nonnegative inputs omit leading zeros, except that zero returns "0". Do not include a sign or a binary prefix.

Function

toBinary(n: int) → String

Examples

Example 1

n = 10return = 1010

Ten equals 8+2, so its binary representation is 1010.

Example 2

n = 0return = 0

Zero returns the single character 0.

Constraints

  • -2147483648 <= n <= 2147483647
  • Negative inputs use exactly 32 two's-complement bits.

More The Walt Disney Company problems

  • Find All Paths for a Name in a File SystemPHONE SCREEN · Seen Nov 2026
  • Resizable Array-Backed Integer SetPHONE SCREEN · Seen Sep 2026
  • Shortest Path with Directional Move CostsPHONE SCREEN · Seen Sep 2026
All The Walt Disney Company interview questionsSee The Walt Disney Company hiring insights
Saved
class Solution {
    public String toBinary(int n) {
        // Write your code here
    }
}

Not a valid String

Checking account…