Multiply Two Arbitrary-Precision Numbers Stored as Digit Lists
Last updated: November 29, 2026
Quick Overview
Two non-negative integers are stored as singly linked lists of decimal digits, most significant first. Return their product as a new linked list in the same format without converting either number to a built-in integer.
0
0
0 solved
Two non-negative integers are stored as singly linked lists of decimal digits, most significant first. Return their product as a new linked list in the same format without converting either number to a built-in integer.
Asked at Google as a step up from linked list addition, in a framing of exact arithmetic for financial reports in Sheets. The interviewer wants schoolbook multiplication with correct carry handling, leading zero stripping, and a discussion of faster algorithms.
What the Interviewer Expects
- Read digits into arrays since multiplication needs random access
- Accumulate products into a result array at index i + j + 1
- Propagate carries from right to left
- Strip leading zeros but keep a single 0 for a zero product
- Mention Karatsuba for very long 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
- Multiply three numbers efficiently.
- Use base 10^9 limbs. What changes and why is it faster?
- Explain Karatsuba's complexity and when it pays off.
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: heads
aandb, digits MSB first, no leading zeros unless the number is 0. - Output: new list for a * b, MSB first.
- No conversion to int for the arithmetic....
High-Level Design
Multiplication pairs every digit of one number with every digit of the other, which is awkward with forward-only access, so first copy each list's digits into an array (O(m + n) space, smaller than th...