I stumbled upon an algorithm problem of which I want an optimised approach. Here goes,
Suppose I have a linked-list which is sorted. Each element of the linked list may have a down pointer which contains a List which is sorted too.
What is the best memory and time efficient way to merge such a list with the subsequent down list?
For eg,
1 -> 5 -> 10 -> 60 -> 100
| | |
20 50 101
| |
30 70
This should get converted to:
1 -> 5 -> 10 -> 20 -> 30 -> 50 -> 60 -> 70 -> 100 -> 101
Data structure for linked list:
Node {
Node next;
List down;
Integer value;
}
Thanks in advance :)