Easy · Arrays

Rotate array

Given an integer array nums and an integer k ≥ 0, rotate nums to the right by k steps in place, so the last k % n values move to the front in their original order. Nothing is returned: nums itself is the result.

Examples

Example 1

[1,2,3,4,5,6,7] k=3

Output: [5,6,7,1,2,3,4]

Example 2

[-1,-100,3,99] k=2

Output: [3,99,-1,-100]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Arrays problems