You're given a 0-indexed integer array nums that might contain elements in decreasing order. Your task is to make this array non-decreasing by repeatedly removing problematic elements.
In each step, you must simultaneously remove all elements nums[i] where nums[i - 1] > nums[i] for all valid indices 0 < i < nums.length. Think of this as a "filtering" process where smaller elements that come after larger elements get eliminated in each round.
Goal: Return the number of steps required until the array becomes non-decreasing (i.e., each element is greater than or equal to the previous element).
Example: [5, 3, 4, 4, 7, 3, 6, 11, 8, 5, 11]
Step 1: Remove 3, 3, 8, 5 → [5, 4, 4, 7, 6, 11, 11]
Step 2: Remove 4, 4, 6 → [5, 7, 11, 11]
Step 3: Remove 5 → [7, 11, 11]
Total: 3 steps
Input & Output
Constraints
- 1 ≤ nums.length ≤ 105
- 1 ≤ nums[i] ≤ 109
- Array elements can be equal (non-decreasing, not strictly increasing)