← Back to challenges

Non-Decreasing List

PythonHardarraysconditionsloopsvalidation

Instructions

Given a list of numbers create a solution to check if this list could become non-decreasing by modifying at most 1 element; return True or False as the result of the evaluation. A list is non-decreasing if each element (except the last one) is less or equal to the next one.

Examples

non_decreasing([4, 2, 3]) ➞ True

non_decreasing([4, 2, 1]) ➞ False

non_decreasing([3, 4, 2, 3]) ➞ False

non_decreasing([5, 7, 1, 8]) ➞ True

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.