So I have a function that performs just fine on small lists. It's function is to check if removing one element from the sequence will make the sequence a strictly increasing sequence:
def almostIncreasingSequence(sequence):
length = len(sequence)
for i in range(1, length):
newSequence = sequence[:i-1] + sequence[i:]
if checkIfSorted(newSequence, length):
return True
return checkIfSorted(sequence[:length-1], length)
def checkIfSorted(sequence, length):
for i in range(1, length - 1):
if sequence[i-1] >= sequence[i]:
return False
return True
But I need it to work on lists up to 100,000 elements long. What sort of optimizations could I make for this to work faster? Right now, it's abysmally slow on lists of 100,000, working through a few thousand elements a second.