Limit Repeats

Imagine a list of orders or events where each value is allowed to appear only a limited number of times. Given a list array and a number n, return a new list where each element appears no more than n times. Keep the remaining elements in the same order as in the original list.

Примеры

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

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

def delete_nth(array: list[int], n: int) -> list[int]:

Теги

arrayhashmap
PostgreSQLv16

Her vises resultatet af din kode

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