Rotated Array Queries
A circular right shift works like a carousel: the last element moves to the front, and the others move one position to the right. The function circular_array_rotation receives an array a, the number of shifts k, and a list of indices queries. After all rotations, find the elements at the requested indices. Return the answers as a list in the same order as the queries.
Примеры
Ввод
[1, 2, 3], 2, [0, 1, 2]Вывод
[2, 3, 1]Ввод
[3, 4, 5], 1, [0, 1, 2]Вывод
[5, 3, 4]Ввод
[1, 2, 3, 4], 0, [0, 3]Вывод
[1, 4]Нужно реализовать
def circular_array_rotation(a: list[int], k: int, queries: list[int]) -> list[int]:
Теги
arraymath
Logi sisse, et näha esituste ajalugu
Logi sisseLogi sisse, et kasutada AI mentorit
Logi sisseVisible tests
1
Input
[1,2,3], 2, [0,1,2]Expected
[2,3,1]2
Input
[3,4,5], 1, [0,1,2]Expected
[5,3,4]3
Input
[1,2,3,4], 0, [0,3]Expected
[1,4]4
Input
[1,2], 3, [0,1]Expected
[2,1]5
Input
[10,20,30,40,50], 4, [1,3]Expected
[30,50]6
Input
[3,2,1], 4, [0,0,0]Expected
[1,1,1]Focus radio
Paused · SomaFM · Fluid