Loading problem…
Given k sorted lists (arrays), merge them into one globally sorted array.
A brute-force approach is to flatten everything and sort once, but interviewers usually expect a better merge strategy that uses the fact each list is already sorted.
Implement:
function mergeKSortedLists(lists) {}Behavior expectations:
mergeKSortedLists([
[1, 4, 5],
[1, 3, 4],
[2, 6],
]); // [1, 1, 2, 3, 4, 4, 5, 6]
mergeKSortedLists([]); // []