Interleave Two Halves

Imagine a list made of two halves that need to be woven together one item at a time. Given a list nums of length 2n, where the first half comes before the second half, return a new list that alternates between them. Take the first item from the first half, then the first item from the second half, then the second from each half, and so on.

Примеры

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

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

def shuffle(nums: list[int], n: int) -> list[int]:

Теги

array
PostgreSQLv16
Entre para enviar

O resultado da execução do código aparecerá aqui

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