New update is available. Click here to update.

Posted: 5 Oct, 2020

Difficulty: Moderate

```
You just need to return the head of the new linked list.
In case the linked list ends after adding K nodes, where K is any positive integer less than 'N'.Append the sum of those K nodes at the end of the linked list.
```

```
The first line of input contains an integer 'T' representing the number of Test cases.
The next 2 * 'T' lines denote the T test cases. Each test case consists of two lines.
The first line of each test case contains the elements of the Linked list separated by space and the linked list is terminated by -1.
The second line of each test case contains two integers separated by a single space denoting 'N' and 'M' respectively, where in the linked list, after every 'M' nodes, take the sum of the next 'N' nodes and append that sum to the linked list.
```

```
For each test case, return the modified linked list with elements separated by space.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= n <= 10^4
1 <= N <= 10^4
1 <= M <= 10^4
-10^5 <= VAL <= 10^5
Where 'n' denotes the length of the linked list and 'VAL' represents a node value of the linked list.
Time limit: 1 sec
```

SIMILAR PROBLEMS

Deletion In Doubly Linked List

Posted: 22 Apr, 2022

Difficulty: Easy

Insertion In Doubly Linked List

Posted: 24 Apr, 2022

Difficulty: Easy

LRU Cache

Posted: 10 Sep, 2022

Difficulty: Moderate

Delete Nodes On Regular Intervals

Posted: 19 Dec, 2022

Difficulty: Ninja

Add One To Linked List

Posted: 19 Dec, 2022

Difficulty: Hard

Categories:

Popular Courses: