FunctionRacerProblemsRace

Rotate Array

EasyArraysPython, JavaScript, TypeScript, Java, C++

Rotate nums to the right by k steps, in place. One step moves every item one place to the right and sends the last item to the front.

Return nothing. k may be larger than the length of the list.

Example 1

nums [1,2,3,4,5,6,7]
k 3
returns [5,6,7,1,2,3,4]

The list becomes [5, 6, 7, 1, 2, 3, 4].

Example 2

nums [1,2]
k 5
returns [2,1]

Five steps on two items is the same as one step: [2, 1].

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems