I am trying to make a function that for a sequence of integers as an array can determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array. If an element can be remove than the output is True otherwise return False. I tried,
def almostIncreasingSequence(sequence):
if sequence[:-1] == sequence[1::]:
return True
else:
return False
It works for list,
sequence = [1, 3, 2, 1]
>>> False
Since you cannot remove any number that would lead to an increasing sequence. However, if the list was
sequence: [1, 3, 2]
>>> True
It is true since you can remove 2 or 3 to have an increasing sequence. My function incorrectly outputs False though.