2289. Steps to Make Array Non-decreasing

Medium

1.1K

114

You are given a **0-indexed** integer array `nums`

. In one step, **remove** all elements `nums[i]`

where `nums[i - 1] > nums[i]`

for all `0 < i < nums.length`

.

Return *the number of steps performed until *`nums`

* becomes a non-decreasing array*.

**Example 1:**

Input:nums = [5,3,4,4,7,3,6,11,8,5,11]Output:3Explanation:The following are the steps performed: - Step 1: [5,,4,4,7,3,6,11,3,8,11] becomes [5,4,4,7,6,11,11] - Step 2: [5,5,4,7,4,11,11] becomes [5,4,7,11,11] - Step 3: [5,6,7,11,11] becomes [5,7,11,11] [5,7,11,11] is a non-decreasing array. Therefore, we return 3.4

**Example 2:**

Input:nums = [4,5,7,7,13]Output:0Explanation:nums is already a non-decreasing array. Therefore, we return 0.

**Constraints:**

`1 <= nums.length <= 10`

^{5}`1 <= nums[i] <= 10`

^{9}

Accepted

15.1K

Submissions

72.3K

Acceptance Rate

20.9%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved