Count UPI Spans With Exactly K High-Value Transfers
A UPI risk monitor flags spans of consecutive transactions that contain exactly k high-value (above-threshold) transfers. Count how many such spans occur in a day's stream.
Problem
Given an array amounts of UPI transaction amounts, a threshold value, and an integer k, a transaction is 'high-value' if its amount is strictly greater than threshold. Count the number of contiguous subarrays that contain exactly k high-value transactions. Return that count.
Input
An integer array amounts, an integer threshold, and an integer k.
Output
An integer: the number of subarrays with exactly k high-value transactions.
Constraints
- 1 <= amounts.length <= 5 * 10^4
- 1 <= amounts[i] <= 10^7
- 0 <= k <= amounts.length
Examples
Example 1
Input
amounts = [1000,50000,2000,80000,300], threshold = 10000, k = 2
Output
6
Two high-value transfers (50000, 80000); six spans contain exactly both.
Example 2
Input
amounts = [200,300,400], threshold = 10000, k = 0
Output
6
No high-value transfers; all 6 subarrays contain exactly zero.