FunctionRacerProblemsRace

Crossing Above

HardNumPyPython

The k-day average on day t is the mean of the k prices that end on day t, so it exists from day k - 1 on.

Count the days t on which the short-day average is above the long-day average while on day t - 1 it was not. Both averages must exist on both days. No loops: for and while are not allowed.

Example 1

prices [10,10,10,1,1,30,30,30]
short 2
long 4
returns 1

With 2 and 4 day averages the short one is below the long one on days 3 and 4, then moves above it on day 5 and stays there: one crossing.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems