dsa · easy
Rotate Array
GreyOrangeArrayTwo PointersFoundation
Rotate nums to the **right** by k steps. Return the rotated array.
Arguments
nums— the input array of integersk— how many steps to rotate right (kmay be larger than the array length)
**Example:** [1,2,3,4,5,6,7], k=3 → [5,6,7,1,2,3,4].
Constraints
1 <= nums.length <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,2,3,4,5,6,7] 3 Expected: [5,6,7,1,2,3,4]
Example 2
Input: [-1,-100,3,99] 2 Expected: [3,99,-1,-100]