A weather station logs one temperature reading every hour throughout the morning and expects the readings to be strictly increasing as the day warms up. A single faulty sensor glitch may have inserted exactly one bad reading somewhere in the log (or the log may already be perfectly fine). Determine whether it is possible to delete at most one reading from the log — keeping all remaining readings in their original order — so that what remains is strictly increasing.
n — the number of readings.n space-separated integers — the readings, in the order they were recorded.Print YES if at most one deletion can make the sequence strictly increasing, otherwise print NO.
Example 1
Input
5 1 2 10 5 7
Expected
YES
Explanation
The sequence 1, 2, 10, 5, 7 first breaks strict order at index 2 (10 >= 5). Removing the 10 leaves 1, 2, 5, 7, which is strictly increasing, so one deletion suffices: YES.
Example 2
Input
5 5 4 7 11 9
Expected
NO
Explanation
The sequence 5, 4, 7, 11, 9 first breaks order at index 0 (5 >= 4). Removing the 5 leaves 4, 7, 11, 9, which still fails (11 >= 9). Removing the 4 instead leaves 5, 7, 11, 9, which also fails (11 >= 9). No single deletion fixes both violations, so the answer is NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →