Here is the interview question prompt, presented for reference.
You're given an array of multiple sorted linked lists. Can you write a method that returns it transformed into a single sorted linked list?
Each linked list
can be represented as a series of nodes with the following definition:
function Node(val) {
this.value = val;
this.next = null;
}
Here's how it would be invoked:
// Input
const arr = [
2 -> 6 -> 9,
1 -> 2 -> 7,
2 -> 6 -> 10
]
mergeLists(arr);
// Output
1 -> 2 -> 2 -> 2 -> 6 -> 6 -> 7 -> 9 -> 10
100000
nodes100000
-1000000000
and 1000000000
n
and k
be the length of a linked list and number of listsO(n*k*log k)
O(k)
You can see the full challenge with visuals at this link.
Challenges • Asked almost 7 years ago by Jake from AlgoDaily
This is the main discussion thread generated for Merge Multiple Sorted Lists.