Given an array of integers and a non-negative integer k, return a new array with the elements of nums rotated k positions to the right. If k exceeds the array length, the rotation wraps around.
Input
nums: array of integers
k: number of positions to rotate right
Output
A new array rotated k positions to the right.
Examples
Example 1
Inputnums = [1, 2, 3, 4, 5], k = 3
Output[3, 4, 5, 1, 2]
Example 2
Inputnums = [10, 20], k = 2
Output[10, 20]
Explanation: Rotating by the array length returns the original order.
Constraints
k >= 0; k may exceed the array length.
Do not mutate the input.