56. Rotate an Array Left by K
Core1000 ms256 MBSolved by 0%
Rotate the array left by k positions and print the result, separated by
single spaces.
Rotating [1, 2, 3, 4, 5] left by 2 gives 3 4 5 1 2, the first two elements move to
the end.
k may be larger than the array length, and may be zero.
Constraints - `1 ≤ n ≤ 200000` - `0 ≤ k ≤ 1000000000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
The third line contains an integer k.
Output
Print the rotated array on ONE line, separated by single spaces.
Input5
1 2 3 4 5
2
Output3 4 5 1 2
Noteis the worked example from the statement
Input5
1 2 3 4 5
0
Output1 2 3 4 5
Noterotates by zero, so nothing moves
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.