EElastic·DSAEngineerTechnical Phone Screen
Merge K Sorted Lists
Problem
Merge k sorted lists into one (analogous to merging postings lists in search).
Example
[[1,4,5],[1,3,4],[2,6]] -> [1,1,2,3,4,4,5,6]
Constraints
- 0 ≤ k ≤ 10^4
Approach
Min-heap of heads, O(N log k).
added 6 days ago