Add Two Binary Strings From a Bitmap Sync Job
Last updated: November 29, 2026
Quick Overview
Two services report counters as binary strings that may be thousands of digits long. Return their sum as a binary string without converting the whole string to an integer.
Meta
November 29, 20260
0
0 solved
Two services report counters as binary strings that may be thousands of digits long. Return their sum as a binary string without converting the whole string to an integer.
A Meta phone-screen staple: carry handling with two pointers. The interviewer checks that you avoid built-in big-integer conversion when asked, handle unequal lengths, and do not leave a trailing carry behind.
What the Interviewer Expects
- Walk both strings from the right with a carry
- Handle unequal lengths without padding copies
- Append the final carry
- Build the output in a list and reverse once
- State linear time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Generalize to any base b.
- How would you add k binary strings at once?
- What if the strings arrive as streams from most significant bit first?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: two non-empty strings of '0' and '1', no leading zeros except the string "0". Output: their sum in binary. Lengths up to around 10^4, so avoid quadratic string concatenation. The interviewer ex...
High-Level Design
Use indices i and j at the ends of a and b and a carry starting at 0. Each step adds the available digits plus carry; the output digit is total & 1 (or total % 2), and the new carry is `total >> 1...