Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3510 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1156 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 642 |

@jha8768 | 577 |

@Run_for_life | 574 |

@divyagupta221100 | 557 |

@AkashLahoty | 538 |

@aayushdesai01 | 526 |

@riyakumaribkj | 526 |

@2017akku | 521 |

@amansinha74458 | 503 |

Complete Leaderboard |

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. Replace the second half nodes with the first half nodes with initial values of 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.

**User Task:**

The task is to complete the function **modifyTheList**() which should modify the list as required.

**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

**Explanation:
Testcase 1**: After modifying the linked list as required, we have new linked list containing the elements as -4, -1, 5, 4, 10.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Modify Linked List-1

...