Editorial for Longest Increasing Sequence


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.
by: doncho

Solutions

  1. O(n) solution in Python
def solve(numbers):
    best_len = 1
    current_len = 1
    prev_number = numbers[0]

    for current_number in numbers[1:]:
        if prev_number < current_number:
            current_len += 1
        else:
            current_len = 1
        prev_number = current_number

        best_len = max(best_len, current_len)

    return best_len

Comments

There are no comments at the moment.