Rotate Array Left by K Positions

M · mediumPracticearrays

Given an array of N elements, rotate it to the left by K positions.

Input
5 2
1 2 3 4 5
Output
3 4 5 1 2
Reverse method: reverse first K, reverse last N-K, reverse whole array.
← Reverse Words in a SentenceRotate Array Right by 1 Position →
Report an issue with this question