Rotate an Array Right (Set 1)

Medium

Given an array of integers nums and a whole number k, rotate the array to the right by k positions and return the result.

k may be larger than the array; rotating by nums.length is a no-op.

Rotate an Array Right (Set 1) — the data. This set runs 4 cases: nums holds arrays of 2–10 items, with values from -20 to 17; k ranges over 0–9. The hidden cases are the largest of the set.

Example 1

rotateArrayRight()
Input
nums = [-6, 4], k = 0
Output
[-6, 4]

Why

`rotateArrayRight` returns `[-6, 4]` for this input.

Example 2

rotateArrayRight()
Input
nums = [10, -19, 17, -7, 0, 5, 1], k = 9
Output
[5, 1, 10, -19, 17, -7, 0]

Why

`rotateArrayRight` returns `[5, 1, 10, -19, 17, -7, 0]` for this input.
Constraints
0 <= nums.length <= 10^4
0 <= k <= 10^6
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysTwo Pointers

Implement rotateArrayRight in the editor and return the answer — printing it is never graded.