#K47322. Non-decreasing Array Modification
Non-decreasing Array Modification
Non-decreasing Array Modification
You are given an array of integers. Your task is to determine whether it is possible to modify at most one element in the array so that the array becomes non-decreasing. An array is non-decreasing if for every index \( i \) (\(1 \leq i < n\)), the condition \(a_i \leq a_{i+1}\) holds.
Input Format: The first line contains a single integer \(n\) (the number of elements in the array). The second line contains \(n\) space-separated integers.
Output Format: Print True
if the array can be made non-decreasing with at most one modification, otherwise print False
.
Note: If the array is already non-decreasing, print True
.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(n\) — the number of elements in the array.
- The second line contains \(n\) space-separated integers representing the elements of the array.
outputFormat
Output a single line with either True
or False
depending on whether the array can be made non-decreasing with at most one modification.
3
4 2 3
True
</p>