ALG-E015EasyArrays
Rotate the Queue
Return the array rotated right by k positions. A rotation moves the last value to the front; an empty array remains empty.
Contract
input numbers: integer[]
input k: integer
return integer[]
Constraints
- • k >= 0
- • 0 <= length <= 1000
Examples
Example 1
numbers = [1, 2, 3, 4]
k = 1
→ [4, 1, 2, 3]
Example 2
numbers = [1, 2, 3]
k = 5
→ [2, 3, 1]
5 judge tests (2 shown above). Target complexity: O(n).