Imagine you're building a calculator that works with really big numbers - so big that regular integers can't handle them! In this problem, you're given two numbers represented as linked lists, where each node contains a single digit, and the digits are stored in reverse order.
For example, the number 342 would be represented as 2 → 4 → 3 in the linked list.
Your task is to add these two numbers and return the result as a new linked list, also in reverse order. Don't forget to handle carry-over when the sum of two digits exceeds 9!
Goal: Add two numbers represented as reversed linked lists
Input: Two non-empty linked lists representing non-negative integers
Output: A new linked list representing the sum in reverse order
Input & Output
Visualization
Time & Space Complexity
We traverse both lists once, where m and n are the lengths of the two lists
Space for the result linked list, which has at most max(m,n)+1 nodes
Constraints
- The number of nodes in each linked list is in the range [1, 100]
- 0 ≤ Node.val ≤ 9
- It is guaranteed that the list represents a number that does not have leading zeros
- Both input lists are non-empty