Add Two Binary Strings
Updated
Problem statement
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) → StringExamples
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
0or1. - Return the full exact binary sum.
More PeopleStrong Onsite Interview questions
- Four SumONSITE INTERVIEW · Seen Mar 2026
- LRU Cache OperationsONSITE INTERVIEW · Seen Mar 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Mar 2026
- Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Sep 2025
- Integer to English Words: Up to 20 DigitsONSITE INTERVIEW · Seen Sep 2025
- Word Ladder II: All Shortest TransformationsONSITE INTERVIEW · Seen Sep 2025
- Detect a Cycle in a Linked ListONSITE INTERVIEW · Seen May 2025
- First Nonrepeating CharacterONSITE INTERVIEW · Seen May 2025
- Longest Subarray with a Target SumONSITE INTERVIEW · Seen May 2025
- Lowest Common Ancestor in a BSTONSITE INTERVIEW · Seen May 2025
Similar questions at other companies
- Add BinaryMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Count Times Using at Most Two DigitsLSEG · OALSEG interview questions
- Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
- Swap Two Integers Without a Temporary VariableOracle · ONSITE INTERVIEWOracle interview questions
- Caesar Cipher with a Precomputed AlphabetAmazon · ONSITE INTERVIEW
- Most Cost-Effective MachineCapital One · ONSITE INTERVIEWCapital One interview questions
- Check Whether a Byte Is NonzeroZscaler · ONSITE INTERVIEWZscaler interview questions
- Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions