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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Two pointers
Carry propagation
String building
Binary arithmetic
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported