Help with this question

in a given linked list replace the value ofevery kth element with the sum of its own value and(n-(k-1))th element value


Input: 1->2>5-11-13-14

Output: 15-15-16-16-15->15

Explanation: (1+14) → (2+13) → (5+11) → (5+11) → (2+13) → (1+14)

One thing is u can take a Struct Node *p pointer and make it equal to head of the node and apply while loop p!= NULL and make a vector and store all the values of the linked list. After that take the p pointer and make it equal to head again and do the process again now for every node just update the value of p->data = p->data + v[lenght-(i-1)] and increment i.

1 Like