Add Two Numbers Represented as Linked Lists

Problem Given two non-negative numbers represented as linked lists — one digit per node — add them and return the sum as a linked list.

Input / Output

  • Input: heads of two linked lists l1 and l2, each node holding a single digit 0-9
  • Output: the head of a new linked list representing the sum, in the same digit order as the input

Constraints

  • Digit order is the clarifying question: least-significant-first (reversed) or most-significant-first (forward) changes the whole approach
  • Lists may have different lengths
  • No leading zeros except the number 0 itself; do not convert to an integer — the numbers may exceed 64 bits

Example

  • 342 + 465 = 807 — as reversed lists: [2,4,3] + [5,6,4] → [7,0,8]
  • Tricky case: [9,9] + [1] → [0,0,1] (99 + 1 = 100) — the carry propagates past both lists and needs an extra node
asked …
LeaderboardSalaryAccount
Add Two Numbers Represented as Linked Lists · 2dbi