prices holds a stock's price for each day. An analyst describes the movement they are looking for with an array trend made of -1, 0 and 1: 1 means the price went up the next day, 0 means it stayed the same, -1 means it went down.
A segment of len(trend) + 1 consecutive days fits the trend if, for every j, the move from its j-th day to the next one is the one trend[j] asks for.
Return the number of segments that fit. Segments may overlap.prices=[5, 7, 7, 3, 4, 4, 2], trend=[1, 0, -1] → 2
The trend "up, flat, down" matches the segments [5, 7, 7, 3] and [3, 4, 4, 2].
prices=[9, 8, 7, 6], trend=[-1, -1] → 2
Two falls in a row: [9, 8, 7] and [8, 7, 6]; matching segments may overlap.
prices=[1, 2, 1, 2], trend=[0] → 0
prices) ≤ 100prices[i] ≤ 10⁹trend) < len(prices)trend[j] is -1, 0 or 1prices=[5, 7, 7, 3, 4, 4, 2], trend=[1, 0, -1]
2
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.