Skip to interview prep
Apexed
Problem list115 / 125

115. Merge K Sorted Arrays

HardPriority queues & heaps

Merge k sorted arrays into one sorted array. Aim for O(N log k), where N is the total number of values.

Example 1

Input: lists = [[1, 4, 5], [1, 3, 4], [2, 6]]
Output: [1, 1, 2, 3, 4, 4, 5, 6]

Constraints

  • 0 ≤ k ≤ 10⁴

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Merge K Sorted Arrays — coding interview practice — Apexed