Given an array **arr[]** of positive integers of size **N**. Reverse every sub-array of **K **group elements.

**Input Format:**

The first line of input contains a single integer **T** denoting the number of test cases. Then** T** test cases follow. Each test case consist of two lines of input. The first line of each test case consists of an integer **N**(size of array) and an integer **K** separated by a space. The second line of each test case contains** N** space separated integers denoting the array elements.

**Output Format:**

For each test case, in a new line, print the modified array.

**User Task:**

The task is to complete the function **reverseInGroups**() which reverses elements of the array in groups and returns the array. **The printing of array is done by drivercode**.

**Constraints:**

1 ≤ T ≤ 200

1 ≤ N, K ≤ 10^{7}

1 ≤ A[i] ≤ 10^{18}

**Example:**

**Input**

4

5 3

1 2 3 4 5

4 3

5 6 8 9

4 7

5 6 8 9

8 3

1 2 3 4 5 6 7 8

**Output**

3 2 1 5 4

8 6 5 9

9 8 6 5

3 2 1 6 5 4 8 7

**Explanation:
Testcase 1:** Reversing groups in size k = 3, first group consists of elements 1, 2, 3. Reversing this group, we have elements in order as 3, 2, 1.

Author: rajatjha

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

cs_abhi | 62 |

kya_bolti_public | 56 |

Shubhankar Sharma | 44 |

vermaankush14291 | 42 |

coderquill | 40 |

PiyushPandey4 | 856 |

john_wick | 757 |

ASWATHAMA | 565 |

akhyasharma01 | 547 |

UsfShilpa | 536 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.