You are given a linked list structure, where each node has two pointers:
Only the top most node can have a non-NULL next pointer.
This gives us a set of vertical linked lists and a horizontal linked list with the head nodes of the vertical lists.
Also, all vertical lists are sorted.
Your task is to flatten the lists into a single linked list, which should also be sorted.
The first line contains âTâ denoting no of test cases.
For each test case,
For each test case, a line containing space-separated integers denoting the elements of flattened linked list.
1
4
3 2 3 4
1 3 8
5 8
8 14 26
13 15 22 25
1 3 5 8 8 8 13 14 15 22 25 26
Take a look at the diagram above to understand this better.
1 <= T <= 10
1 <= n <= 100
1 <= Li <= 100
1 <= node value <= 1000