FastPrepCount Strictly Increasing Contiguous Windows
Problem · Array

Count Strictly Increasing Contiguous Windows

Learn this problem
EasyIBM logoIBMNEW GRADOA
See IBM hiring insights

Problem 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) → int

Examples

Example 1

yCoordinates = [6,5,7,8,3,5,6]k = 3return = 2

The valid windows are [5,7,8] and [3,5,6].

Example 2

yCoordinates = [1,2,3,4]k = 3return = 2

Both overlapping windows [1,2,3] and [2,3,4] are valid.

Example 3

yCoordinates = [4,4,5]k = 2return = 1

Equality is not increasing, so only [4,5] counts.

Constraints

  • 1 <= yCoordinates.length <= 10^5.
  • 1 <= k <= yCoordinates.length.
  • 1 <= yCoordinates[i] <= 10^9.

More IBM problems

drafts saved locally
public int countIncreasingWindows(int[] yCoordinates, int k) {
    // Write your code here.
}
yCoordinates[6,5,7,8,3,5,6]
k3
expected2
checking account