Problems > Rotate Right by K

Rotate Right by K

Difficulty: 1000 3000 ms 128 MB

implementation

Rotate the list right by K positions (the last K elements move to the front).

Input: the first line has N and K; the second line has N integers.

Output: the rotated list.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ K ≤ 1018

Sample Tests

Input 1
5 2
1 2 3 4 5
Output 1
4 5 1 2 3
Input 2
3 3
1 2 3
Output 2
1 2 3

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.