Carousel Shift
Imagine a carousel: elements move to the right, and the ones that pass the edge appear again at the beginning. The function rotate_right receives a list nums and shifts it cyclically to the right by k positions, returning a new list. The value of k may be larger than the list length, so remember to account for full rotations.
Примеры
Ввод
([1, 2, 3, 4, 5], 2)Вывод
[4, 5, 1, 2, 3]Ввод
([1, 2, 3], 0)Вывод
[1, 2, 3]Ввод
([1, 2, 3], 3)Вывод
[1, 2, 3]Нужно реализовать
def rotate_right(nums: list[int], k: int) -> list[int]:
Теги
lists
Prihláste sa, aby ste videli históriu odoslaní
Prihlásiť saPrihláste sa, aby ste mohli používať AI mentora
Prihlásiť saVisible tests
1
Input
[1,2,3,4,5], 2Expected
[4,5,1,2,3]2
Input
[1,2,3], 0Expected
[1,2,3]3
Input
[1,2,3], 3Expected
[1,2,3]4
Input
[], 5Expected
[]5
Input
[1,2,3,4], 5Expected
[4,1,2,3]6
Input
[0,0,0], 3Expected
[0,0,0]Focus radio
Paused · SomaFM · Fluid