Given a linked list, you modified that linked list in such a way that the elements of the first half of that linked list are the difference of the first node to the last node and next node is the difference of the second node to the second last node and goes on.
Example:
Input:
4 → 5 → 9 → 3 → 8 → 1 → 2 → 5
Output:
-1 → 3 → 8 → -5 → 8 → 1 → 2 → 5
Input:
6 → 5 → 4 → 9 → 1 → 2 → 7
Output:
-1 → 3 → 3 → 9 → 1 → 2 → 7
Algorithm:
To solve the problem we can follow this algorithm:
C++ implementation:
Output