Reverse in Groups
Reverse in Groups
You will be provided with N Numbers and an Integer K. You have to create a doubly linked list and then insert the given numbers into it. After Insertion, You have to reverse the newly formed Doubly Linked List in the Groups of Size 'K'.
Input Format
The First line will contain two Integers N and K. The Next line will contain N Integers separated by whitespaces.
Constraints
Print the Final content of the Doubly Linked List separated by space after performing above operation.
Output Format
1 <= N <= 10^1
1 <= K <= 10^1
N % K == 0
Sample TestCase 1
Input
6 2
10 20 30 40 50 60
Output
20 10 40 30 60 50
Sample TestCase 2
Input
12 2
10 20 30 40 50 60 70 80 90 2 11 12
Output
0
Sample TestCase 3
Input
11 2
10 20 30 40 50 60 70 80 90 2 11
Output
0
Explanation
First Group = (10, 20) -> (20, 10)
Second Group = (30, 40) -> (40, 30)
Third Group = (50, 60) -> (60, 50)
2nd test case Constraint N not satisfied so output should be 0
3rd test 11 mod 2 is not 0 constraint not satisfied
Comments