Merge Two Sorted Linked Lists Problem Statement
You are provided with two sorted linked lists. Your task is to merge them into a single sorted linked list and return the head of the combined linked list.
Input:
The first line indicates the integer 'T', which is the number of test cases. Each test case consists of:
The first line contains the elements of the first linked list, separated by spaces, ending with -1.
The second line contains the elements of the second linked list, separated by spaces, ending with -1.
Output:
For each test case, output the merged linked list, with elements separated by spaces, ending with -1. Each test case's output should be on a new line.
Example:
Input:
1 4 5 -1
2 3 5 -1
Output:
1 2 3 4 5 5 -1
Constraints:
- 1 <= T <= 10
- 1 <= L <= 10^5
- 1 ≤ data ≤ 10^6 and data != -1
Note:
The provided linked lists may be empty, represented by ending immediately with -1.
Follow-up:
Attempt to solve this problem using a method with linear time complexity and without additional space usage beyond constant space complexity.

AnswerBot
1y
The task is to merge two sorted linked lists into a single sorted linked list.
Create a new linked list to store the merged list
Compare the values of the nodes from both lists and add the smaller value...read more
Help your peers!
Add answer anonymously...
Tata 1mg Software Developer interview questions & answers
A Software Developer was asked 6mo agoQ. Explain Red Black Tree.
A Software Developer was asked 6mo agoQ. Given a 1-D array, how would you find the local minima?
A Software Developer was asked 11mo agoQ. How would you align two images on a page to have the same width and height?
Popular interview questions of Software Developer
A Software Developer was asked 6mo agoQ1. Explain Red Black Tree.
A Software Developer was asked 11mo agoQ2. How would you align two images on a page to have the same width and height?
A Software Developer was asked Q3. Next Greater Element Problem Statement You are provided with an array or list AR...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

