You are given an array of integers nums.
Your task is to apply Stalin sort: iterate through the array from left to right, keeping the first element and any subsequent element that is greater than or equal to the last kept element, removing all others.
You may assume that:
Return the resulting array.
[3, 1, 2, 4, 1, 5]
[3, 4, 5]
Keep 3 (first element). 1 < 3, remove. 2 < 3, remove. 4 >= 3, keep. 1 < 4, remove. 5 >= 4, keep.
[1, 2, 3]
[1, 2, 3]
The array is already non-decreasing, so all elements are kept.
[3, 2, 1]
[3]
2 < 3 and 1 < 3, so only the first element remains.
[3, 1, 2, 4, 1, 5]
[3, 4, 5]