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
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution