Add Two Gift Card Balances Stored as Forward Digit Lists

Last updated: November 29, 2026

Quick Overview

Two very large gift card balances are stored as singly linked lists of digits, most significant digit first. Return their sum as a new list in the same format without reversing the input lists.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Two very large gift card balances are stored as singly linked lists of digits, most significant digit first. Return their sum as a new list in the same format without reversing the input lists.

Amazon interviewers use this as a twist on the classic reversed-digit addition, with the constraint that the inputs are read-only. They check that you choose stacks (or recursion) to align digits and that carry propagation at the front is handled.

What the Interviewer Expects
  • Recognize digits must be aligned from the least significant end
  • Use two stacks to process digits right to left without mutating inputs
  • Build the output by prepending nodes
  • Handle a final carry that adds a new leading digit
  • Discuss the recursion alternative and its stack depth
Key Topics to Cover
linked lists
stacks
big number arithmetic
carry propagation
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
  • How would you do it with O(1) extra space if you were allowed to mutate the inputs?
  • How would you subtract the balances instead?
  • What changes if each node stores four digits (base 10000)?
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

Each list holds digits 0 to 9, most significant first, with no leading zeros except the number 0 itself. The inputs must not be modified (other services read them). Output a new list, most significant...

High-Level Design

Push the digits of each list onto its own stack. Then pop from both stacks together, adding the two digits plus the carry. Each sum digit becomes a new node that is prepended to the result, which natu...


Submit Your Answer
Markdown supported