![]() |
VOOZH | about |
Given n binary strings, the task is to find their sum which is also a binary string.
Examples:
Input: arr[] = ["1101", "111"]
Output: "10100"
Explanation:
👁 Add-two-binary-strings-using-Bit-by-Bit-addition
Input : arr[] = ["1", "10", "11"]
Output : "110"
A simple idea is to initialise res = "0" and preform addition of each string with res one by one. The value of res after adding all binary strings is the final answer.
For adding res and arr[i], we use the approach used in Add two binary strings.
110
Time Complexity: O(n * maxLen), where n is the size of the array and maxLen is maximum length of any binary string.
Auxiliary Space: O(maxLen), for result string.