#K64197. Strictly Increasing Sequence by Removal
Strictly Increasing Sequence by Removal
Strictly Increasing Sequence by Removal
You are given a sequence of n integers. Your task is to determine whether it is possible to obtain a strictly increasing sequence by removing at most one element from the sequence. Note that if the sequence is already strictly increasing, you should return True
.
A sequence a1, a2, ..., an is considered strictly increasing if a1 < a2 < ... < an.
Formally, given a sequence \(a_1, a_2, \dots, a_n\), determine if there exists an index \(i\) (possibly no removal is needed) such that after removing \(a_i\) (if necessary) the remaining sequence is strictly increasing.
For example, consider the sequence [1, 3, 2, 1]. Removing any one element does not lead to a strictly increasing sequence, so the answer is False
. In contrast, for the sequence [1, 3, 2] you can remove the element 3
to obtain [1, 2] which is strictly increasing, so the answer is True
.
inputFormat
The input is read from stdin and consists of two lines. The first line contains an integer n representing the number of elements in the sequence. The second line contains n space-separated integers.
outputFormat
Output to stdout a single line containing either True
or False
indicating whether a strictly increasing sequence can be obtained by removing at most one element from the given sequence.## sample
4
1 3 2 1
False