You are given the heads of two sorted linked lists. Merge them into one sorted list.
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]
Topics: linked-list, recursion
Asked by: Amazon, Google, Meta, Microsoft, Apple, Bloomberg
Time complexity: O(n+m). Space complexity: O(1).