In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 22nd
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #06 exercise sheet]


In this problem you should submit a function as described. Inside the function do not print anything that was not asked!

The name of the .py source file you submit to Mooshak should NOT start with a digit (you will get an error if you submit it like that).

[IP063] Neural Activity

Amy Farrah Fowler, neurobiologist and proud holder of a PhD, is studying a fascinating pattern in brainwave readings collected during an experiment with Leonard. The readings are represented as a list of integers, each indicating the neural activation level at a particular moment.

Amy is particularly interested in detecting streaks of increasing brain activity, which might indicate moments of heightened cognitive processing (or possibly, mild irritation at Sheldon).

She defines a reading segment of size k as stimulating if the k consecutive readings are strictly increasing, with each reading larger than the previous one. Can you help Amy count how many such segments exist?

The Problem

Write a function brain_streaks(k, lst) that receives an integer k and a list lst of positive integers, returning the number of contiguous sublists of size k that are strictly increasing.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

1 ≤ k ≤ 50 000       Size of sublists to consider
k ≤ |lst| ≤ 50 000       Number of elements in the list
1 ≤ lst[i] ≤ 109       Readings in the list

NOTE: the limits are high and you must have an efficient solution.
If your code simply tries all possible sublists and for each of them you iterate through all elements of the sublist, it will result in a Time Limit Exceeded.


Example Function Calls Example Output
print(brain_streaks(3, [1, 2, 3, 2, 4, 5]))
print(brain_streaks(3, [1, 2, 2, 1, 2]))
2
0 

Explanation of the first example

The strictly increasing sublists of size 3 are [1, 2, 3] and [2, 4, 5].

Explanation of the second example

There are no strictly increasing sublists of size 3.


Introduction to Programming (CC1024)
DCC/FCUP - University of Porto