Dsa
Linked List
Warm-up
Sum of Linked List Elements
Given a linked list, calculate the sum of its elements. You are to print the result as a single integer.
Input format:
- The first line contains an integer n (0 <= n <= 100), the number of nodes.
- The second line contains n space-separated integers representing the values of each node in the linked list.
Output format:
- A single integer which is the sum of all the elements in the linked list.
Example:
Input:
4
3 7 1 9
Output:
20
Key concepts
linked_listsumtraversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now