Given a linked list, every node of which consists of a pair of integer variables first and second to hold the data, and a pointer pointing to the next node in the list. The task is to find the sum of min(first, second) for every node.
Input: (2, 3) -> (3, 4) – > (1, 10) -> (20, 15) -> (7, 5) -> NULL
2 + 3 + 1 + 15 + 5 = 26
Input: (7, 3) -> (3, 9) -> (5, 10) -> (20, 8) -> (19, 11) -> NULL
3 + 3 + 5 + 8 + 11 = 30
Approach: Traverse the whole linked list and for each node if the first element of node is smaller in comparison of second element of that node then we add first element to the variable which is holding the sum, otherwise we add the second element.
Below is the implementation of the above approach:
- Delete all the nodes from a doubly linked list that are smaller than a given value
- Replace even nodes of a doubly linked list with the elements of array
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Delete N nodes after M nodes of a linked list
- Linked List Sum of Nodes Between 0s
- Sum of the alternate nodes of linked list
- Linked List Product of Nodes Between 0s
- Sum of the nodes of a Circular Linked List
- Sum of all odd frequency nodes of the Linked List
- Sum and Product of all the nodes which are less than K in the linked list
- Sum of all distinct nodes in a linked list
- Sum of the nodes of a Singly Linked List
- Find the sum of last n nodes of the given 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.