Add Binary

Given two binary strings a and b, return their sum as a binary string. Pattern focus: Bit Addition. Simulate binary addition with carry from the least significant bit to the most significant bit.

Input Format

a, b = binary strings

Output Format

binary string sum

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • a, b must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

a = "11"
b = "1"

Output:

100

Explanation:

11 + 1 = 4, which is 100 in binary.

Example 2:

Input:

a = "1010"
b = "1011"

Output:

10101

Explanation:

10 + 11 = 21, which is 10101 in binary.

Loading...
Add Binary - Bit Manipulation DSA Problem