Imagine you're a quality control engineer for a data visualization company. You receive arrays of numerical data that should display as smooth, ascending charts - but sometimes there's exactly one data point that's out of place!
Given an array nums with n integers, determine if you can make it non-decreasing by modifying at most one element. An array is considered non-decreasing when nums[i] <= nums[i + 1] for every valid index i.
Your mission: Return true if the array can be fixed with one change (or is already perfect), false otherwise.
Example: [4,2,3] → Change the 4 to 1, getting [1,2,3] ✅[4,2,1] → Would need to change both 4 and 2 ❌
Input & Output
Visualization
Time & Space Complexity
Single pass through the array, each element visited once
Only using constant extra space for counters and variables
Constraints
- 1 ≤ nums.length ≤ 104
- -105 ≤ nums[i] ≤ 105
- At most one element can be modified