Problem of the day
Input: ‘A’ = 2, ‘B’ = 2, ‘N’ = 8, ‘head’ = [1, 2, 3, 4, 5, 6, 7, 8]
Output: [1, 2, 5, 6]
Explanation: Keep the first A(2) nodes, delete the next B(2) nodes, and continue until we have reached the end of the linked list.
First-line contains 'T', denoting the number of Test cases.
For each Test case:
The first line contains two integers, ‘A’ and ‘B’, denoting the number of nodes to keep and the number of nodes to delete.
The second line contains one integer, ‘N’, denoting the number of nodes in the linked list.
The third line contains N integers denoting the number of nodes in the linked list.
Return the head of the linked list after modifying the linked list as said above.
You don't need to print anything. Just implement the given function.
1 <= T <= 10
1 <= N <= 1e3
1 <= A, B <= 100
The value of each node in the linked list is in the range [1 to 1e9]
Time Limit: 1-sec
2
2 2
8
1 2 3 4 5 6 7 8
2 3
4
10 20 30 40
1 2 5 6
10 20
For test case 1:
Input: ‘A’ = 2, ‘B’ = 2, ‘N’ = 8, ‘head’ = [1, 2, 3, 4, 5, 6, 7, 8]
Output: [1, 2, 5, 6]
Explanation: Keep the first A(2) nodes, delete the next B(2) nodes, and continue until we have reached the end of the linked list.
For test case 2:
Input: ‘A’ = 2, ‘B’ = 2, ‘N’ = 8, ‘head’ = [1, 2, 3, 4, 5, 6, 7, 8]
Output: [1, 2, 5, 6]
Explanation: Keep the first A(2) nodes, delete the next B(3) nodes, and continue until we have reached the end of the linked list.
2
10 10
1
8
1 1
4
9 8 7 6
8
9 7