This challenge already describes dropsort. However, I'm kinda lazy and I really only need my array to be a bit more sorted than before, it doesn't need to be sorted all the way.
In Drop Sort, we drop every element less than any element before it. In Lazy Drop Sort, we drop every element less than the one strictly preceding it.
Here's an example. Consider the following array:
8 6 9 9 7 2 3 8 1 3
Let's mark every element less than the one before it.
8 6 9 9 7 2 3 8 1 3
^ ^ ^ ^
Notice how neither 3
was marked, nor the last 8
. They are all larger than the single element to the left of them.
Completing the algorithm, removing the marked elements, we get:
8 9 9 3 8 3
That basically looks more sorted. Kinda. I'm lazy.
Your task, as you may have already deduced, is to implement this algorithm.
Input is an array of at least 1 positive integer between 1 and 9, so you can take a string of digits as well.
This is code-golf, fewest bytes wins!
Additional test cases:
1
1
1 2 3
1 2 3
5 3 1
5
1 2 3 2 1
1 2 3
1 1 1 9 9 9 1 1 1 9 9 9 1 1 1
1 1 1 9 9 9 1 1 9 9 9 1 1
9 9
9 9
5 2 4 2 3
5 4 3