#C8086. Non-Decreasing Sequence by Removing One Element
Non-Decreasing Sequence by Removing One Element
Non-Decreasing Sequence by Removing One Element
Given an array of integers of length ( n ), determine whether it is possible to remove exactly one element so that the resulting sequence becomes non-decreasing. A sequence (a_1, a_2, \dots, a_m) is non-decreasing if (a_i \le a_{i+1}) for all valid indices. Your task is to check every possibility of removing one element and verify if the modified sequence meets the requirement.
inputFormat
The first line contains an integer ( n ) representing the number of elements in the sequence. The second line contains ( n ) space-separated integers denoting the sequence.
outputFormat
Print "YES" if it is possible to remove exactly one element to make the sequence non-decreasing. Otherwise, print "NO".## sample
5
4 2 3 3 5
YES