Problem · Array
Count Strictly Increasing Contiguous Windows
Learn this problemProblem statement
The integer array yCoordinates gives the y-coordinate at each consecutive integer x-coordinate. Count contiguous windows of exactly k points whose y-coordinates are strictly increasing from left to right.
For this exercise, assume overlapping windows count separately. A window beginning at start is valid when yCoordinates[i] < yCoordinates[i + 1] for every index from start through start + k - 2.
Function
countIncreasingWindows(yCoordinates: int[], k: int) → intExamples
Example 1
yCoordinates = [6,5,7,8,3,5,6]k = 3return = 2The valid windows are [5,7,8] and [3,5,6].
Example 2
yCoordinates = [1,2,3,4]k = 3return = 2Both overlapping windows [1,2,3] and [2,3,4] are valid.
Example 3
yCoordinates = [4,4,5]k = 2return = 1Equality is not increasing, so only [4,5] counts.
Constraints
1 <= yCoordinates.length <= 10^5.1 <= k <= yCoordinates.length.1 <= yCoordinates[i] <= 10^9.