Dsa
Heap
Easy
Merge K Sorted Lists
You are given K sorted linked lists, each represented as a list of integers. Your task is to merge them into a single sorted list. The merged list should also be in sorted order. Print the merged list as a space-separated string of integers.
Input format:
The first line contains an integer K (1 <= K <= 100), the number of linked lists.
The next K lines each contain a space-separated list of integers, where each list is sorted in non-decreasing order. The integers are separated by spaces and the list can be empty.
Output format:
Print a single line containing the merged sorted integers from all lists, separated by spaces.
Example:
Input:
3
1 4 5
1 3 4
2 6
Output:
1 1 2 3 4 4 5 6
Key concepts
heapsortinglists
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now