Merging two Sorted Singly Linked List

Introduction – Merging two Sorted Singly Linked List

This question is mostly asked in interviews and hence I thought of writing few possible solutions to the same. I also asked the same question on stackoverflow.com. You can visit the link here

Problem Statement

You have two singly linked lists that are already sorted, you have to merge them and return the head of the new list without creating any new extra nodes. The returned list should be sorted as well

The method signature is:

Node class is below:

Solution

There can be multiple solutions to the given problem, few of them are given below:

Recursive Solution

Without Recursion

Github Link

Conclusion

Here we learnt to merge two sorted singly linked list without creating any another list. This problem can be solved using recursion, which I personally like. For the non-recursion lovers there is another program written above.

Hope this helps. Stay connected and stay Subscribed