Sum of nodes in a linked list

Given a linked list which include integer elements. Our goal is to find sum of elements which is present in this linked list. We assume that the sum of nodes are not break the maximum and minimum integer.

List : 10 → -2 → 3 → NULL
Output : 11

List : 1 → 5 → 2 → 6 NULL
Output : 14

That is one of the basic problem to traverse linked list node, Which is easily solve using recursion and iterative manner.

Iterative solution

Using Recursion

Accepted time complexity is O(n).



Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved