Here is the interview question prompt, presented for reference.
We're provided the following two linked lists:
1 -> 2 -> 3 -> 4 and 2 -> 5 -> 8
Each one represents a number in reversed order, so 1 -> 2 -> 3 -> 4 represents 4321 and 2 -> 5 -> 8 represents 852 (note: for an extra challenge, consider if they weren't reversed).
The lists are guaranteed to have at least one node and will not have any leading 0s. Each of the nodes contain a single digit.
Can you write a method to add the two numbers and return it as another linked list?
// list1: 1 -> 2 -> 3 ->4
// list2: 2 -> 5 -> 8
addLLNums(list1, list2);
// should return 3 -> 7 -> 1 -> 5
// 4321 + 852 = 5173
list1, list2 <= 1000000 and 9 O(n)O(n)You can see the full challenge with visuals at this link.
Challenges • Asked almost 8 years ago by Team AlgoDaily
This is the main discussion thread generated for Add Linked List Numbers.