A
A
Alexey Anisimov2019-01-04 12:27:47
Python
Alexey Anisimov, 2019-01-04 12:27:47

How to check if an array is ascending?

The task is to check if the sequence is increasing, but there is one "but" - you can remove one element in order to achieve a constant increase in the list.
More details: https://app.codesignal.com/arcade/intro/level-2/2m... .
What is wrong in my solution?

def almostIncreasingSequence(sequince):
    increases = True
    removed = False
    for n in range(1, len(sequince)):
        print(n)
        if sequince[n] <= sequince[n - 1] and not(removed):
            removed = True
            continue
        if sequince[n] <= sequince[n - 1] and removed:
            return False 
    return True

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2019-01-05
@wataru

Your solution doesn't work on example 3,4,1,2. You can't remove a single number here, but your program will return true.
If you have found one section with decreasing neighboring numbers, you need to check what will happen if you remove the first or second number.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question