#3523

Make Array Non-decreasing

medium · 56.8% accepted · 89 likes · top 52%

array · stack · greedy · monotonic stack

Description

You are given an integer array nums. In one operation, you can select a subarray and replace it with a single element equal to its maximum value.

Return the maximum possible size of the array after performing zero or more operations such that the resulting array is non-decreasing.

Solution