Add Two Binary Digit Strings

Quick Overview

Add two canonical binary digit strings and return their exact sum in binary, including zero and long input representations.

Add Two Binary Digit Strings

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem The strings `first` and `second` represent nonnegative integers in base two. Return their sum as a binary digit string, using the usual representation without unnecessary leading zeroes. ### Examples **Example 1** ```text Input: first = "1101", second = "101" Output: "10010" ``` The represented values are `13` and `5`; their sum, `18`, is written as `10010` in binary. **Example 2** ```text Input: first = "0", second = "1001" Output: "1001" ``` Adding zero preserves the other value. ### Constraints - Each input string has length between `1` and `10^4`, inclusive. - The only permitted characters are `0` and `1`. - Each input has no leading zeroes unless the entire string is `"0"`.

Overview: Add two canonical binary digit strings and return their exact sum in binary, including zero and long input representations.

Google logo
Google
Oct 14, 2026
easySoftware EngineerOtherCoding & Algorithms
1
0

Problem

The strings first and second represent nonnegative integers in base two. Return their sum as a binary digit string, using the usual representation without unnecessary leading zeroes.

Examples

Example 1

Input: first = "1101", second = "101"
Output: "10010"

The represented values are 13 and 5; their sum, 18, is written as 10010 in binary.

Example 2

Input: first = "0", second = "1001"
Output: "1001"

Adding zero preserves the other value.

Constraints

  • Each input string has length between 1 and 10^4 , inclusive.
  • The only permitted characters are 0 and 1 .
  • Each input has no leading zeroes unless the entire string is "0" .