Swap Stack Pairs
The stack is given as a list: the bottom is on the left, and the top is on the right. Given stack, go through its elements from bottom to top in pairs. Swap the two elements in each pair. If there is an odd number of elements, leave the final top element unchanged.
Примеры
Ввод
[3, 8, 17, 9, 1, 10]Вывод
[8, 3, 9, 17, 10, 1]Ввод
[3, 8, 17, 9, 1]Вывод
[8, 3, 9, 17, 1]Ввод
[]Вывод
[]Нужно реализовать
def switch_pairs(stack: list[int]) -> list[int]:
Теги
stack
Zaloguj się, aby zobaczyć historię rozwiązań
Zaloguj sięZaloguj się, aby korzystać z Mentora AI
Zaloguj sięTests12
Visible tests
Ukryty test 7
Ukryty test 8
Ukryty test 9
Ukryty test 10
Ukryty test 11
Ukryty test 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid