Given a linked list, the task is to find the maximum sum for any contiguous nodes.
Input: -2 -> -3 -> 4 -> -1 -> -2 -> 1 -> 5 -> -3 -> NULL
4 -> -1 -> -2 -> 1 -> 5 is the sub-list with the given sum.
Input: 1 -> 2 -> 3 -> 4 -> NULL
Approach: Kadane’s algorithm has been discussed in this article to work on arrays to find the maximum sub-array sum but it can be modified to work on linked lists too. Since Kadane’s algorithm doesn’t require to access random elements, it is also applicable on the linked lists in linear time.
Below is the implementation of the above approach:
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Maximum sum of K consecutive nodes in the given Linked List
- 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
- Delete N nodes after M nodes of a linked list
- Linked List Sum of Nodes Between 0s
- Find the sum of last n nodes of the given Linked List
- Sum of the nodes of a Circular Linked List
- Sum of the alternate nodes of linked list
- Find sum of even and odd nodes in a 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
- Linked List Product of Nodes Between 0s
- Sum of the nodes of a Singly Linked List
- Sum of all odd frequency nodes 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 email@example.com. 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.