Given two linked list of the same size, the task is to create a new linked list using those linked lists. The condition is that the greater node among both linked list will be added to the new liked list.
Input: list1 = 5->2->3->8 list2 = 1->7->4->5 Output: New list = 5->7->4->8 Input: list1 = 2->8->9->3 list2 = 5->3->6->4 Output: New list = 5->8->9->4
Approach: We traverse both the linked list at the same time and compare node of both lists. The node which is greater among them will be added to the new linked list. We do this for each node.
First List: 5->2->3->8-> Second List: 1->7->4->5-> New List: 5->7->4->8->
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Create a linked list from two linked lists by choosing max element at each position
- Sum of nodes in a linked list which are greater than next node
- Create linked list from a given array
- Convert singly linked list into circular linked list
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Difference between Singly linked list and Doubly linked list
- Delete all the nodes from the doubly linked list that are greater than a given value
- Create a Doubly Linked List from a Ternary Tree
- Create a sorted linked list from the given Binary Tree
- Swap Kth node from beginning with Kth node from end in a Doubly Linked List
- Delete linked list nodes which have a greater value on left side
- Swap Kth node from beginning with Kth node from end in a Linked List
- Remove Nth node from end of the Linked List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.