Add Two Numbers II

MediumLinked Listsimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Two non-negative integers are stored as linked lists l1 and l2, one decimal digit per node, with the **most significant digit first**. Neither number has leading zeros, except the number 0 itself (a single node holding 0). Return the head of a new linked list holding their sum in the same most-significant-first format, again without leading zeros. The numbers may be far larger than 64-bit integers, so add digit by digit. Follow-up: solve it without reversing the input lists.

Examples

Input: l1 = [7,2,4,3], l2 = [5,6,4]
Output: [7,8,0,7]
7243 + 564 = 7807.
Input: l1 = [2,4,3], l2 = [5,6,4]
Output: [8,0,7]
243 + 564 = 807.
Input: l1 = [0], l2 = [0]
Output: [0]
0 + 0 = 0.

Constraints

  • 1 <= number of nodes in each list <= 100
  • 0 <= Node.val <= 9
  • No leading zeros except for the number 0 itself

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems