Reverse in Groups

Medium · rating 1350 · Arrays

The first line has n and k. The second line has n integers. Reverse the array in contiguous groups of k (a final group smaller than k is reversed as-is). Print the result, space-separated.

Constraints: 1 ≤ k ≤ n ≤ 105

Related problems

Open Reverse in Groups in Code Arena →