164. Add Binary Strings

EasyStringString

Given two binary strings a and b, return their sum as a binary string.

Both strings consist only of '0' and '1' characters.
The input strings do not have leading zeros except for '0' itself.

You must NOT convert the strings to integers directly.

Input: Two comma-separated binary strings: a and b.

Output: A binary string representing the sum of a and b.

Examples

Example 1
Input: 11,1
Output: 100
Explanation: 11 (3) + 1 (1) = 4 = 100 in binary.
Example 2
Input: 1010,1011
Output: 10101
Explanation: 1010 (10) + 1011 (11) = 21 = 10101 in binary.
Example 3
Input: 0,0
Output: 0
Explanation: 0 + 0 = 0.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →