3523. Make Array Non-decreasing Medium
1/**
2 * [3523] Make Array Non-decreasing
3 *
4 * You are given an integer array nums. In one operation, you can select a <span data-keyword="subarray-nonempty">subarray</span> and replace it with a single element equal to its maximum value.
5 * Return the maximum possible size of the array after performing zero or more operations such that the resulting array is non-decreasing.
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [4,2,5,3,5]</span>
10 * Output: <span class="example-io">3</span>
11 * Explanation:
12 * One way to achieve the maximum size is:
13 * <ol>
14 * Replace subarray nums[1..2] = [2, 5] with 5 → [4, 5, 3, 5].
15 * Replace subarray nums[2..3] = [3, 5] with 5 → [4, 5, 5].
16 * </ol>
17 * The final array [4, 5, 5] is non-decreasing with size <font face="monospace">3.</font>
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [1,2,3]</span>
22 * Output: <span class="example-io">3</span>
23 * Explanation:
24 * No operation is needed as the array [1,2,3] is already non-decreasing.
25 * </div>
26 *
27 * Constraints:
28 *
29 * 1 <= nums.length <= 2 * 10^5
30 * 1 <= nums[i] <= 2 * 10^5
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/make-array-non-decreasing/
36// discuss: https://leetcode.com/problems/make-array-non-decreasing/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn maximum_possible_size(nums: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_3523() {
54 }
55}
56Back
© 2026 bowen.ge All Rights Reserved.