AlgoFrames

Add two binary strings

Challenge · Write code · about 12 min

a and b are binary numbers written as strings. Return their sum as a binary string.

Work from the right and keep a carry, as in the lesson.

Example 1

Input:

["101","11"]

Output:

1000

5 + 3 = 8.

Example 2

Input:

["0","0"]

Output:

0

Constraints

  • 1 ≤ a.length, b.length ≤ 5,000
  • a and b contain only 0 and 1
  • No leading zeros except the single digit 0

Learn the idea first: Bits, bytes and binary numbers, a visual lesson.

More Bits, bytes and binary numbers problems