Merge Two Sorted Lists
You are given the heads of two sorted linked lists represented as arrays `list1` and `list2`. Merge the two lists into one sorted list and return it as an array. **Examples:** ```typescript mergeTwoLists([1, 2, 4], [1, 3, 4]) // [1, 1, 2, 3, 4, 4] mergeTwoLists([], []) // [] mergeTwoLists([], [0]) // [0] ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(n + m)
- Space complexity: O(1)
Linear scan comparing front elements of list1 (n) and list2 (m).
Follow-Up Questions Interviewers Ask About Merge Two Sorted Lists
- How does a dummy head node simplify linked list operations?
A dummy head eliminates special conditional checks for assigning the initial head pointer of the merged list.
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.