As reported: PayPal Senior Software Engineer (2026), first DSA round: LeetCode Steps to Make Array Non-decreasing, with a variation.
You are given an array nums. In one step, remove every element nums[i] with nums[i - 1] > nums[i] (all removals in a step happen at once, judged on the array as it was at the start of the step). Return the number of steps performed until nums becomes non-decreasing.
This is LeetCode 2289 — Steps to Make Array Non-decreasing.
Example 1
nums = [5,3,4,4,7,3,6,11,8,5,11] -> 3
step 1: [5,4,4,7,6,11,11]
step 2: [5,4,7,11,11]
step 3: [5,7,11,11]
Example 2
nums = [4,5,7,7,13] -> 0
Constraints: 1 ≤ nums.length ≤ 10^5; 1 ≤ nums[i] ≤ 10^9.
Code runner format: one JSON value per line (LeetCode's test-case format): nums. Implement totalSteps(nums); the harness prints the number.