Your question is Linked List: Add Two Numbers. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Lytx may represent large event-count values as linked lists to avoid fixed-width integer limits. Given two non-negative integers stored in reverse digit order, return their sum in the same linked-list format.
Each node contains one decimal digit. The head node stores the least significant digit. The lists may have different lengths, and the result must not contain unnecessary leading zero nodes, except when the sum is zero.
Implement add_two_numbers(l1, l2), where l1 and l2 are heads of singly linked lists whose node values are integers from 0 through 9. Return the head of a new singly linked list representing l1 + l2 in reverse digit order. The provided environment defines ListNode with fields val and next.
For test cases, each linked list is written as a JSON array for readability, and the evaluator converts it to a linked list before calling the function. The expected result is written as an array of node values.
def add_two_numbers(l1, l2):