Merge two sorted linked lists
Company: Two Sigma
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency with linked list data structures, pointer manipulation, in-place merging concepts, and algorithmic efficiency within the Coding & Algorithms domain.
Constraints
- 0 <= n, m <= 100000, where n and m are the lengths of the two lists
- -10^9 <= node value <= 10^9
- Both input lists are sorted in non-decreasing order
Examples
Input: ([1, [2, [4, None]]], [1, [3, [4, None]]])
Expected Output: [1, [1, [2, [3, [4, [4, None]]]]]]
Explanation: Merge by repeatedly taking the smaller front node: 1, 1, 2, 3, 4, 4.
Input: (None, [0, [2, None]])
Expected Output: [0, [2, None]]
Explanation: If one list is empty, the result is simply the other list.
Input: ([-3, [1, [5, None]]], [-4, [2, [6, None]]])
Expected Output: [-4, [-3, [1, [2, [5, [6, None]]]]]]
Explanation: Merging the sorted lists produces -4 -> -3 -> 1 -> 2 -> 5 -> 6.
Input: (None, None)
Expected Output: None
Explanation: Both lists are empty, so the merged list is also empty.
Input: ([1, [1, [2, None]]], [1, [3, None]])
Expected Output: [1, [1, [1, [2, [3, None]]]]]