Add Two Big Integers Stored Most Significant Digit First
Last updated: November 29, 2026
Quick Overview
Two non-negative integers are stored as singly linked lists of digits with the most significant digit first. Return their sum in the same order without reversing either input list.
0
0
0 solved
Two non-negative integers are stored as singly linked lists of digits with the most significant digit first. Return their sum in the same order without reversing either input list.
An onsite variant at Google that removes the convenient digit order to see if you reach for a stack or a length-aligned recursion. The interviewer probes the memory cost of each approach and whether you can build the result head-first.
What the Interviewer Expects
- Explain why left-to-right order blocks straightforward carry
- Use two stacks (or length alignment with recursion) to process from the right
- Build the result by prepending nodes so no final reversal is needed
- Handle a final carry by prepending one more node
- Respect the no-mutation constraint on the inputs
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
- Do it with O(1) extra space besides the output.
- Multiply instead of add.
- The lists are streamed and you cannot store them. Is it possible?
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:
aandb, digits MSB first, no leading zeros except 0. - Output: new list for a + b, MSB first.
- Do not reverse or modify the inputs....
High-Level Design
Carry flows from right to left, but singly linked lists walk left to right. The cleanest fix is to push each list's digits onto a stack, then pop from both stacks, which yields digits least significan...