Rotate Array Right
Updated
Problem statement
You are given an integer array nums and an integer k. Rotate the array to the right by k steps and return the rotated array.
Function
rotateRight(nums: int[], k: int) → int[]Examples
Example 1
nums = [1,2,3,4,5,6,7]k = 3return = [5,6,7,1,2,3,4]Moving the last three values to the front gives [5,6,7,1,2,3,4].
Example 2
nums = [-1,-100,3,99]k = 2return = [3,99,-1,-100]After two right rotations, 3 and 99 move to the front.