Rotate an Array by K Positions
Mediumjavapythonccppjavascript
Given an array of N integers and an integer K, rotate the array to the right by K positions.
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the rotated array as N space-separated integers on one line.
Example 1
Input
5 2 1 2 3 4 5
Output
4 5 1 2 3
Explanation: The last two elements move to the front.
- 1 <= N <= 100000
- 0 <= K <= 1000000000
- -1000000000 <= A[i] <= 1000000000