Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the array.
Below is the Python3 code that I used and it worked fine:
def almostIncreasingSequence(sequence):
flag = False
if(len(sequence) < 3):
return True
if(sequence == sorted(sequence)):
if(len(sequence)==len(set(sequence))):
return True
bigFlag = True
for i in range(len(sequence)):
if(bigFlag and i < len(sequence)-1 and sequence[i] < sequence[i+1]):
bigFlag = True
continue
tempSeq = sequence[:i] + sequence[i+1:]
if(tempSeq == sorted(tempSeq)):
if(len(tempSeq)==len(set(tempSeq))):
flag = True
break
bigFlag = False
return flag