The longest rising run

Find the longest stretch of a list in which each value is larger than the one before.

What to build

One pass through a list, remembering two numbers.

Requirements

  • Read the list.
  • Print the length of the longest run of neighbours in strictly increasing order.

Input

The first line has n. The second line has n whole numbers.

Output

One number.

Constraints

n is from 1 to 1000.

Example

Input:

5
1 2 3 2 5

Output:

3

Why it works

Each item either extends the current run or starts a new one, so nothing needs to be looked at twice.

Examples

Example 1 · Input
5
1 2 3 2 5
Expected output
3
Example 2 · Input
3
5 4 3
Expected output
1

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Keep the length of the current run and the best length so far.

Hint 2

If an item is larger than the one before it, the run grows. Otherwise it starts again at 1.

Hint 3

Start looping from the second item, so that there is always an item before.

Solution

Show one correct solution (try it yourself first)
n = int(input())
nums = [int(x) for x in input().split()]
best = 1
run = 1
for i in range(1, n):
    if nums[i] > nums[i - 1]:
        run += 1
    else:
        run = 1
    if run > best:
        best = run
print(best)

Lesson: Lists →