Search for a command to run...
You are given an array of integers nums
You are also given an integer k
Your task is to rotate the array to the right by k steps
Each step moves elements one position to the right
The last element moves to the front
Input:
nums = [1, 2, 3, 4, 5, 6, 7]
k = 3Output:
[5, 6, 7, 1, 2, 3, 4]You must modify the array in-place
Do not use extra space (O(1) space only)
1 ≤ nums.length ≤ 10⁵
-10⁹ ≤ nums[i] ≤ 10⁹
0 ≤ k ≤ 10⁹
Example 1
[1, 2, 3, 4, 5, 6, 7], 3[5,6,7,1,2,3,4]Example 2
[1, 2, 3], 3[1,2,3]Example 3
[1, 2], 0[1,2][1, 2, 3, 4, 5, 6, 7], 3
[5,6,7,1,2,3,4]