Question

Write a function that sums the values of given linked list?

Login to Submit

Examples

Linked list will be created like this:

let a = {val:1, next:null};
let b = {val:2, next:null};
let c = {val:3, next:null};
let d = {val:4, next:null};
let e = {val:5, next:null};

a.next = b;
b.next = c;
c.next = d;
d.next = e;

Since a is the head of the linked list the function solve() will be called like this:

solve(a)

For questions asking the modification of the given linked list, you must return the head of the same linked list after the operation asked by the question is complete.