Add Two Huge Like Counts Stored as Decimal Strings
Last updated: November 29, 2026
Quick Overview
Two non-negative integers are given as decimal strings that may be too long for any native integer type. Return their sum as a string without converting either input to an integer directly.
Meta
November 29, 20260
0
0 solved
Two non-negative integers are given as decimal strings that may be too long for any native integer type. Return their sum as a string without converting either input to an integer directly.
A classic Meta warm-up that tests careful digit-by-digit arithmetic. Interviewers watch for clean carry handling, unequal lengths, and avoiding quadratic string concatenation.
What the Interviewer Expects
- Does not call int() on the full strings
- Walks both strings from the right with a carry
- Handles different lengths and a final carry
- Builds the result in a list and reverses once
- Tests with carries that ripple through every digit
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
- How would you support negative numbers?
- Extend it to multiply two decimal strings.
- How would you add numbers given in an arbitrary base b?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs contain only digits, no leading zeros except the number 0 itself. Output must follow the same format. O(max(m, n)) time is expected....
High-Level Design
Use two indices starting at the last character of each string and a carry. At each step, take the digit at each index (or 0 once an index runs off the front), add them with the carry, append `total ...