Rotate an Array Right (Set 2)

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 2) — the data. This set runs 4 cases: nums holds arrays of 8–18 items, with values from -19 to 20; k ranges over 0–9. The hidden cases are the largest of the set.

Example 1

rotateArrayRight()
Input
nums = [2, 5, -12, -5, -1, -7, 8, -6, -14, -8, 4, -5, -9, -7], k = 9
Output
[-7, 8, -6, -14, -8, 4, -5, -9, -7, 2, 5, -12, -5, -1]

Why

`rotateArrayRight` returns `[-7, 8, -6, -14, -8, 4, -5, -9, -7, 2, 5, -12, -5, -1]` for this input.

Example 2

rotateArrayRight()
Input
nums = [16, -19, -12, -8, 5, 3, -5, -16], k = 0
Output
[16, -19, -12, -8, 5, 3, -5, -16]

Why

`rotateArrayRight` returns `[16, -19, -12, -8, 5, 3, -5, -16]` 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.