Separate Index Sorting

Here the important part is not the value itself, but whether its position is even or odd. Write a function sort_even_odd that sorts the numbers at even indices in ascending order. Sort the numbers at odd indices in descending order. Return a new list where each group goes back only into its own type of positions.

Примеры

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

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

def sort_even_odd(nums: list[int]) -> list[int]:

Теги

arraysorting
PostgreSQLv16

Тук ще се появи резултатът от изпълнението на кода

Visible tests
1
Input
[4,1,2,3]
Expected[2,3,4,1]
2
Input
[2,1]
Expected[2,1]
3
Input
[1]
Expected[1]
4
Input
[5,4,3,2,1]
Expected[1,4,3,2,5]
5
Input
[3,3,3,3]
Expected[3,3,3,3]
6
Input
[9,1,8,2,7,3]
Expected[7,3,8,2,9,1]
Focus radio
Paused · SomaFM · Fluid