Skip to content
Decoder

Add Binary

Easy

Problem

a and b are binary strings (only '0' and '1'). Return their sum, also as a binary string.

Example 1

Input
a = "11", b = "1"
Output
"100"

Example 2

Input
a = "1010", b = "1011"
Output
"10101"

Example 3

Input
a = "0", b = "0"
Output
"0"

Constraints

  • 1 <= a.length, b.length <= 10^4
  • a and b consist only of '0' or '1' characters.
  • Neither string has leading zeros, except the number zero itself.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.