Skip to content

Practice Non-decreasing Array

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

Medium#665
LeetCode Problem

Non-decreasing Array

Problem Statement

Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element. We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based) such that (0 <= i <= n - 2).

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

Examples

# Example 1

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

# Example 2

Input
nums = [4,2,1]
Output
false

Constraints

n == nums.length
1 <= n <= 10^4
-10^5 <= nums[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Non-decreasing Array.

Review your practice with PhantomCodeAI

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