Keep the Order

This unusual sort does not move elements around; it removes anything that breaks the order. Walk through sequence from left to right and keep a number only if it is not smaller than every number already kept. Return the non-decreasing list of surviving elements.

Примеры

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

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

def stalin_sort(sequence: list[int]) -> list[int]:

Теги

sorting
PostgreSQLv16
Entre para enviar

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

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