Right Array Rotation

A cyclic shift works like a carousel: elements from the end move to the front, and the rest shift to the right. The function rotate_array receives an array nums and a number k. Rotate the array to the right by k positions and return the new order. If k is larger than the array length, use only the remainder after full rotations.

Примеры

Ввод
[[1, 2, 3, 4, 5, 6, 7], 3]
Вывод
[5, 6, 7, 1, 2, 3, 4]
Ввод
[[-1, -100, 3, 99], 2]
Вывод
[3, 99, -1, -100]
Ввод
[[1, 2], 3]
Вывод
[2, 1]

Нужно реализовать

def rotate_array(nums, k):

Теги

arraymath
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

Visible tests
1
Input
[1,2,3,4,5,6,7], 3
Expected[5,6,7,1,2,3,4]
2
Input
[-1,-100,3,99], 2
Expected[3,99,-1,-100]
3
Input
[1,2], 3
Expected[2,1]
4
Input
[1], 0
Expected[1]
5
Input
[], 4
Expected[]
6
Input
[1,2,3], 3
Expected[1,2,3]
Focus radio
Paused · SomaFM · Fluid