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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Arrays problems