Ctrl K

Sum of Binary Strings

Easy
You are given two strings left and right, each a non-negative integer written in binary. Return their sum, also as a binary string. The inputs have no leading zeros, except when the number itself is zero (then the string is "0"). The answer must not have leading zeros either.
Example 1
left='101', right='11' → '1000'

5 + 3 = 8, which is 1000 in binary.

Example 2
left='0', right='110' → '110'

Adding zero changes nothing: 0 + 6 = 6.

Example 3
left='1111', right='1' → '10000'

15 + 1 = 16: the carry ripples through every digit and adds a new one.

Constraints
  • 1 ≤ left.length, right.length ≤ 10⁴
  • Both strings contain only the characters '0' and '1'
  • No leading zeros, except for the string "0" itself
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasyA String That Copies Itself EasyTop of a Digit Pyramid EasyMultiplying Digit Strings Medium
loading Python…
Input
left='101', right='11'
Expected
'1000'

Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.