Question bank › Linked List
Dsa Linked List Medium

Merge K Sorted Linked Lists

You are given K linked lists, each one sorted in ascending order. Your task is to merge all these linked lists into a single sorted linked list. The merged linked list should be in ascending order. Write a program that reads the number of linked lists K, followed by K lines where each line contains a space-separated list of integers representing the nodes of each linked list (with -1 indicating the end of that linked list). Print the merged linked list as a space-separated string of integers. Input Format: - The first line contains an integer K (1 <= K <= 100). - Each of the next K lines contains a series of integers ending with -1. Output Format: - A single line with the merged linked list as a space-separated string of integers, ending with -1. Example: Input: 3 1 4 5 -1 1 3 4 -1 2 6 -1 Output: 1 1 2 3 4 4 5 6 -1

Key concepts

linked_listsortingmerge

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.