Last Even Values

Sometimes you need to take only the last matching values from a large list while keeping their original order. Write a function even_numbers that takes a list arr and a number n. First find all even numbers, then return the last n of them in the same order they appeared in the original list.

Примеры

Ввод
[1, 2, 3, 4, 5, 6, 7, 8, 9], 3
Вывод
[4, 6, 8]
Ввод
[-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2
Вывод
[-8, 26]
Ввод
[6, -25, 3, 7, 5, 5, 7, -3, 23], 1
Вывод
[6]

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

def even_numbers(arr: list[int], n: int) -> list[int]:

Теги

listsarray
PostgreSQLv16

Hier verschijnt het resultaat van je code

Visible tests
1
Input
[1,2,3,4,5,6,7,8,9], 3
Expected[4,6,8]
2
Input
[-22,5,3,11,26,-6,-7,-8,-9,-8,26], 2
Expected[-8,26]
3
Input
[6,-25,3,7,5,5,7,-3,23], 1
Expected[6]
4
Input
[2,4,6,8], 4
Expected[2,4,6,8]
5
Input
[2,4,6,8], 2
Expected[6,8]
6
Input
[1,2,3,4,5,6,7,8,9], -3
Expected[8]
Focus radio
Paused · SomaFM · Fluid