Easy15 pts
Rotate Array
Given an array, rotate it to the right by k steps. Example: [1,2,3,4,5,6,7], k=3 → Rotate right 3 times → [5,6,7,1,2,3,4] Optimized approach: Use the reversal algorithm - reverse entire array, reverse first k, reverse rest.
Input
Line 1: n k (array size and rotation count). Line 2: n space-separated integers.
Output
The rotated array as space-separated integers.
Sample
7 3 1 2 3 4 5 6 7
Expected
5 6 7 1 2 3 4
Loading editor…
Output
No output yet. Run your code to see results.