Algorithms

Rotate Array

mediumalgorithmsarrayrotation
0:00

Problem

Rotate the array `nums` to the right by `k` steps, where `k` is non-negative. Return the rotated array.

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Rotate Array is a medium algorithms coding challenge. It tests algorithmic thinking and complexity analysis — the kind of problem-solving that shows up constantly in technical interviews. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Normalize k with k = k % nums.length. If k === 0 return a copy. Otherwise return nums.slice(-k).concat(nums.slice(0, -k)).

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.