FastPrepAdd Two Binary Strings
Problems/Add Two Binary Strings

Add Two Binary Strings

PeopleStrong logoPeopleStrong● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names binary-string addition with optimization and dry runs. The interface, bounds and leading-zero normalization are authored; core similarity is about 90%.

Given two nonempty binary strings a and b, return their sum as a binary string. Each input contains only 0 and 1 and represents a nonnegative integer.

For this exercise, assume inputs may contain leading zeros. The returned representation must have no leading zeros unless the sum is zero, in which case return 0. The strings may be too long for built-in fixed-width integers.

Function

addBinaryStrings(a: String, b: String) → String

Examples

Example 1

a = "1011"b = "1101"return = "11000"

The inputs represent 11 and 13; their sum 24 is binary 11000.

Example 2

a = "000"b = "0"return = "0"

The sum is zero, whose normalized representation is a single 0.

Constraints

  • For this exercise, assume 1 <= a.length, b.length <= 10^5.
  • Every character is 0 or 1.
  • Return the full exact binary sum.

More PeopleStrong problems

  • Four SumONSITE INTERVIEW · Seen Mar 2026
  • LRU Cache OperationsONSITE INTERVIEW · Seen Mar 2026
  • Reverse Linked-List Nodes in Groups of KOA · PHONE SCREEN · Seen Mar 2026
All PeopleStrong interview questionsSee PeopleStrong hiring insights
Saved
class Solution {
    public String addBinaryStrings(String a, String b) {
        // Write your solution here.
    }
}
Checking account…