java.lang.Object
g2201_2300.s2289_steps_to_make_array_non_decreasing.Solution

public class Solution extends Object
2289 - Steps to Make Array Non-decreasing.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>. In one step, <strong>remove</strong> all elements <code>nums[i]</code> where <code>nums[i - 1] > nums[i]</code> for all <code>0 < i < nums.length</code>.</p> <p>Return <em>the number of steps performed until</em> <code>nums</code> <em>becomes a <strong>non-decreasing</strong> array</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [5,3,4,4,7,3,6,11,8,5,11]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> The following are the steps performed:</p> <ul> <li> <p>Step 1: [5, <strong>3</strong> ,4,4,7, <strong>3</strong> ,6,11, <strong>8</strong> , <strong>5</strong> ,11] becomes [5,4,4,7,6,11,11]</p> </li> <li> <p>Step 2: [5, <strong>4</strong> ,4,7, <strong>6</strong> ,11,11] becomes [5,4,7,11,11]</p> </li> <li> <p>Step 3: [5, <strong>4</strong> ,7,11,11] becomes [5,7,11,11]</p> </li> </ul> <p>[5,7,11,11] is a non-decreasing array. Therefore, we return 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [4,5,7,7,13]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> nums is already a non-decreasing array. Therefore, we return 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • totalSteps

      public int totalSteps(int[] nums)