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->
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Create a linked list from two linked lists by choosing max element at each position
- Sum of two numbers if the original ratio and new ratio obtained by adding a given number to each number is given
- Sum of nodes in a linked list which are greater than next node
- Count of greater elements for each element in the Array
- Next greater element in the Linked List
- Smallest subarray of size greater than K with sum greater than a given value
- Insert a node in Linked List before a given node
- Reverse each word in a linked list node
- C Program to reverse each node value in Singly Linked List
- Replace each node with its Surpasser Count in Linked List
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Modify given array by reducing each element by its next smaller element
- Delete all the nodes from the doubly linked list that are greater than a given value
- Count of distinct possible pairs such that the element from A is greater than the element from B
- Swap Kth node from beginning with Kth node from end in a Linked List
- Swap Kth node from beginning with Kth node from end in a Doubly Linked List
- Longest subarray in which absolute difference between any two element is not greater than X
- Replace every node of a Linked list with the greatest element on right side
- Delete a given node in Linked List under given constraints
- Create linked list from a given array
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.