Merge Two Sorted Linked Lists
Company: LinkedIn
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: Merge two sorted linked lists by relinking nodes with a dummy head, preserving duplicates and handling empty inputs in linear time and constant space.
Read the full LinkedIn Machine Learning Engineer interview experience this question came from
Constraints
- The lists are disjoint, acyclic, and nondecreasing, with at most 2^31 − 1 values combined.
- Values are integers from −(2^53 − 1) through 2^53 − 1, inclusive.
Examples
Input: ([1, 3, 5], [2, 4, 6])
Expected Output: [1, 2, 3, 4, 5, 6]
Explanation: The two input lists interleave.
Input: ([0, 2, 2], [-1, 2, 4])
Expected Output: [-1, 0, 2, 2, 2, 4]
Explanation: All three occurrences of 2 appear in the result.
Hints
- Every occurrence of a value belongs in the result, even if it appears in both lists.