How do you add two numbers represented by linked lists?

Coding
Medium
Amazon
145K views

This question simulates arithmetic operations on large numbers stored in linked lists. It tests digit-by-digit addition with carry propagation.

Why Interviewers Ask This

Representing numbers as linked lists removes the limitation of integer overflow. Interviewers want to see if candidates can implement basic arithmetic logic manually and handle carries correctly across list nodes.

How to Answer This Question

Traverse both lists simultaneously, adding corresponding digits along with any carry from the previous position. Create a new node for the result digit. Continue until both lists are exhausted and no carry remains. Handle lists of different lengths by treating missing digits as zero.

Key Points to Cover

  • Add digits with carry
  • Handle different list lengths
  • Create new result list
  • Finalize carry if needed

Sample Answer

I will iterate through both lists, summing the values of the current nodes and the carry. The result digit is sum modulo 10, and the new carry is sum divided by 10. I create a new node for each result digit. If one list ends, I continue with the other list, treating missing nodes as zero.

Common Mistakes to Avoid

  • Ignoring the final carry
  • Modifying input lists instead of creating new ones
  • Incorrect carry calculation

Practice This Question with AI

Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.

Start Practicing

Related Interview Questions

Browse all 26 Coding questionsBrowse all 125 Amazon questions