Loading...
Loading...
Loading...
A library has k shelves. The books on each shelf are listed by number in ascending order. Merge all k lists into one ascending list and print it. A shelf can be empty.
Example 1
Input
3 3 1 4 9 2 2 3 1 5
Output
1 2 3 4 5 9
Merging gives 1 2 3 4 5 9.
Example 2
Input
2 0 1 7
Output
7
Try the problem first. Open one hint at a time.
Keep one front value per shelf in a heap, with its shelf index and position.
After popping a value, push the next value from the same shelf.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor