0
Determine whether its possible to obtain a strictly increasing sequence by removing no more than one element from the array.
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. For sequence [1, 3, 2, 1], the output should be: almostIncreasingSequence(sequence) = false; There is no one element in this array that can be removed in order to get a strictly increasing sequence. For sequence [1, 3, 2], the output should be: almostIncreasingSequence(sequence) = true. You can remove 3 from the array to get the strictly increasing sequence [1, 2]. Alternately, you can remove 2 to get the strictly increasing sequence [1, 3].
5 Réponses
+ 2
Hello Veeee
Please do not expect people to solve your homework for you. You need to show some effort, or at least explain, which part gives you trouble.
https://www.sololearn.com/Discuss/333866/?ref=app
Some ideas:
You can use list slicing, to create a new sequence skipping one specific element.
You can use the zip function to create pairs of values inside the sequence, like a sliding window that looks at two neighboring values at a time, and compare each pair to validate if the sequence is increasing.
There are lots of ways to solve this problem, and whatever is suggested by others, may not match your knowledge level. That's why you should give it a try first, and not just copy someone else's code.
0
def almostIncreasingSequence(sequence):
c= 0
for i in range(len(sequence)-1):
if sequence[i]>=sequence[i+1]:
c +=1
return c<1
All the test cases ain't passing tho
0
Yeah of course, Thanks for the ideas