Given an array transactions of transaction amounts and an integer k, count the number of contiguous subarrays of length exactly k that are strictly increasing.
A subarray is strictly increasing if every element is strictly greater than the element before it. Return the total count of such subarrays.
Function Signature
def count_increasing_segments(transactions: list[int], k: int) -> int:
...
Rules
-
Subarrays are counted by position. Two windows that start at different indices count separately, even when they hold the same values.
-
Equal neighbors are not increasing, so a window that contains two equal adjacent values does not count.
-
A single element is strictly increasing on its own, so for
k = 1
the answer is
len(transactions)
.
Constraints
-
1 <= len(transactions) <= 10^5
-
1 <= k <= len(transactions)
-
-10^9 <= transactions[i] <= 10^9
Examples
Input: transactions = [1, 2, 3, 4, 5], k = 3
Output: 3
The strictly increasing subarrays of length 3 are [1, 2, 3], [2, 3, 4] and [3, 4, 5], giving a count of 3.
Input: transactions = [5, 4, 3, 2, 1], k = 2
Output: 0
No pair of consecutive elements is strictly increasing, so the count is 0.
Input: transactions = [1, 3, 3, 4, 5, 6], k = 3
Output: 2
There are four windows of length 3. [1, 3, 3] and [3, 3, 4] contain the equal pair 3, 3 and fail, while [3, 4, 5] and [4, 5, 6] are strictly increasing.