VOOZH about

URL: https://www.geeksforgeeks.org/dsa/add-n-binary-strings/

⇱ Add n binary strings - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Add n binary strings

Last Updated : 31 Aug, 2025

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"

[Approach] Bit-by-bit addition with carry

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.


Output
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.

Comment
Article Tags: