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
Accedi per vedere la cronologia degli invii
AccediAccedi per usare l'AI Mentor
AccediVisible tests
1
Input
[1,2,3,4,5,6,7], 3Expected
[5,6,7,1,2,3,4]2
Input
[-1,-100,3,99], 2Expected
[3,99,-1,-100]3
Input
[1,2], 3Expected
[2,1]4
Input
[1], 0Expected
[1]5
Input
[], 4Expected
[]6
Input
[1,2,3], 3Expected
[1,2,3]Focus radio
Paused · SomaFM · Fluid