Your question is Addition of Two Linked Lists. 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.
ThoughtSpot can represent large numeric values as digit streams when the values exceed native integer limits. Given two non-empty linked lists, add the represented non-negative integers and return the sum as a linked list.
Each node contains one decimal digit, and the least significant digit appears first. The result must also use reverse digit order. Do not convert either linked list into a built-in integer or string.
Use a ListNode with fields val and next. The function add_two_numbers(l1, l2) receives the heads of two linked lists and returns the head of a newly created linked list representing their sum. The input lists may have different lengths. Input values do not contain leading zeroes unless the number itself is zero.
For test cases, lists are shown as Python arrays for readability. The harness converts each array to a linked list before calling the function and serializes the returned list back to an array.
def add_two_numbers(l1, l2):