2dbi
Home/PlanetScale/Merge K Sorted Lists
PPlanetScale·DSAEngineerTechnical Phone Screen

Merge K Sorted Lists

Problem

Merge k sorted lists (analogous to merging sorted results from k shards).

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
LeadersAccount