Given two binary strings, return their sum (also a binary string).
Input: a = "11", b = "1" Output: "100"
We strongly recommend you to minimize your browser and try this yourself first
The idea is to start from last characters of two strings and compute digit sum one by one. If sum becomes more than 1, then store carry for next digits.
Thanks to Gaurav Ahirwar for suggesting above solution. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Add n binary strings
- XOR of two Binary Strings
- Bitwise AND of N binary strings
- Bitwise OR of N binary strings
- Generate all binary strings without consecutive 1's
- Generate all binary strings from given pattern
- XOR two binary strings of unequal lengths
- Count of binary strings of given length consisting of at least one 1
- Count number of binary strings of length N having only 0's and 1's
- Count binary strings with twice zeros in first half
- Count of non-overlapping sub-strings "101" and "010" in the given binary string
- Count number of binary strings without consecutive 1’s : Set 2
- Number of sub-strings in a given binary string divisible by 2
- Count number of binary strings without consecutive 1's
- Number of binary strings such that there is no substring of length ≥ 3
- Given two binary strings perform operation until B > 0 and print the result
- Number of Binary Strings of length N with K adjacent Set Bits
- Generate Binary Strings of length N using Branch and Bound
- Generate all binary strings of length n with sub-string "01" appearing exactly twice
- Find the number of binary strings of length N with at least 3 consecutive 1s