Skip to content

Practice Make Array Non-decreasing

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3523
LeetCode Problem

Make Array Non-decreasing

Problem Statement

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.

Source: Make Array Non-decreasing on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [4,2,5,3,5]
Output
3

# Example 2

Input
nums = [1,2,3]
Output
3

Constraints

1 <= nums.length <= 2 * 10^5
1 <= nums[i] <= 2 * 10^5

Related LeetCode Problems

Practice more problems similar to Make Array Non-decreasing.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.