CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsArrays

Rotate Array

Medium
LeetCode
6/14
MediumArraysLeetCode #189

Rotate Array by k (in-place)

Classic: reverse all, reverse first k, reverse rest. k %= n.

Examples

Example 1

Input

7 3
1 2 3 4 5 6 7

Output

5 6 7 1 2 3 4
Example 2

Input

4 2
-1 -100 3 99

Output

3 99 -1 -100

Stuck? Take a nudge

C++17Autosaves