Right Rotation

Given a list of numbers nums and a non-negative integer k, rotate the list to the right by k positions. The elements from the end move back to the beginning, like the list is wrapping around in a circle. If k is larger than the list length, full extra rotations do not change the result. Return the new rotated list.

Примеры

Ввод
[1, 2, 3, 4, 5], 2
Вывод
[4, 5, 1, 2, 3]
Ввод
[1, 2, 3], 4
Вывод
[3, 1, 2]
Ввод
[], 3
Вывод
[]

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

def rotate_right(nums: list[int], k: int) -> list[int]:

Теги

array
PostgreSQLv16

Koodin suorituksen tulos näkyy tässä

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