Practice · 4 of 6
Rotate right by k
CHALLENGE
Difficulty: advanced+25 XP
Rotate the array **right by k** positions (each element moves forward, wrapping: last becomes first). Mutate the array in place. Implement rotate(int[] arr, int k) where 0 ≤ k (k may exceed length — then it wraps; k % length == 0 changes nothing).
Example: {1,2,3,4,5}, k=2 → {4,5,1,2,3}.
Press Submit to check your solution.
Back to lesson: Practice: Array lab: two passes, write indices, safe removal