- naive approach would be to use a mediating data strucutre
- a priority queue for example to maintain order
- insert elements from priority queue into a new linked list and return the new head
- we can do this without the use of additional auxillary space
- only increment one of the lists at a time
- insert the lower value of the two nodes into the lsit and move its pointer by one
- if one of the lists compeltes before the 2nd list, append the remaining nodes from the second list to the end of the new list
π€What Did I Struggle With?
~
need to use a nullptr node as the initial head of the list
and need to return the next value instead of that dummy nullptr node
π‘ Explanation of Solution
same as intuition
β Complexity Analysis
Time Complexity: O(N)
- iterating through the length of at most 1 lists contents
- as the remaining contents of the larger of the two lists will be inserted directly at the tail of the list
Space Complexity: O(N)
- new list is being constructed of N elements where N is the number of elements in list1 and list2