Math Fundamentals18 sections · 814 units
Open in Course

Problem - Add Binary

LeetCode 67

Given two binary strings aa and bb, return their sum as a binary string. For example, if a="1010"a = "1010" and b="1011"b = "1011", return "10101""10101".

You cannot convert to integers and add, because the inputs can be long (up to 10410^4 characters). You must perform binary addition manually, digit by digit, handling carries.

This is like adding two numbers on paper: start from the right, add digits and carry over when the sum exceeds the base. Before reading on, think about how to track the carry and build the result.