BETA

Difficulty Level: Easy

Submissions: 1693 Accuracy:

30.71%

Modify Linked List-1 (Function Problem)
     

Given a singly linked list containing n nodes. Modify the value of first half nodes such that 1st node’s new value is equal to the last node’s value minus first node’s current value, 2nd node’s new value is equal to the second last node’s value minus 2nd node’s current value, likewise for first half nodes. If n is odd then the value of the middle node remains unchanged.
Note: Input in the linked list is like new node will be entered at the head position (1st position).

Input:
First line consists of T test cases. First line of every test case consists of N, denoting the number of nodes. Second line of every test case consists of Node of linked list.

Output:
Single line output, return the head of modified linked list.

Constraints:
1<=T<=200
1<=N<=100

Example:
Input:

2
5
10 4 5 3 6
6
2 9 8 12 7 10
Output:
-4 -1 5 4 10
8 -2 4 8 9 2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.