1274. Rising Window Count

Easy1.5 points estimatedSliding WindowArray

A fitness app records the number of steps a user walked each day, listed in order in nums. A streak of k consecutive days is called a rising window if the step count is strictly larger on every day than on the day before it inside that streak. A window of a single day (k = 1) is always rising.

Return how many windows of exactly k consecutive days are rising. Windows are counted by their starting position, so two windows with identical values at different positions count separately. Walk through the array once while tracking the length of the strictly increasing run that ends at the current index; a window ending there qualifies when that length is at least k. Aim for O(n) time and O(1) extra space.

Example 1

Input:
nums = [1,2,3,2,3,4], k = 3
Output:
2
Explanation:

The windows [1,2,3] and [2,3,4] are strictly increasing, so the count is 2.

Example 2

Input:
nums = [5,5,5], k = 2
Output:
0
Explanation:

No two neighbouring days increase, so no window of length 2 qualifies.

Constraints

1 ≤ k ≤ nums.length ≤ 1000

-109 ≤ nums[i] ≤ 109

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(n)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…