Question bank › Linked List
Dsa Linked List Hard

Combine Two Sorted Linked Lists

You are given two linked lists that are sorted in ascending order. Your task is to merge these two linked lists into a single sorted linked list, which must also be in ascending order. The resulting list should be constructed by splicing together the nodes of the first two lists. Input format: - The first line contains an integer n (1 <= n <= 1000), the number of nodes in the first list. - The second line contains n integers, which are the values of the nodes in the first linked list, separated by spaces. - The third line contains an integer m (1 <= m <= 1000), the number of nodes in the second list. - The fourth line contains m integers, which are the values of the nodes in the second linked list, separated by spaces. Output format: - A single line containing the values of the merged linked list, separated by spaces. Example: Input: 3 1 3 5 4 2 4 6 8 Output: 1 2 3 4 5 6 8

Key concepts

linked_listsortingmerging

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