You're given an array of integers arr and two important parameters: k (the subarray size) and threshold (the minimum average). Your task is to find how many contiguous subarrays of exactly size k have an average that meets or exceeds the threshold.
Think of it as a quality control problem: you're scanning through data windows of fixed size and counting how many meet your quality standards. For example, if you have test scores [2, 2, 2, 2, 5, 5, 5, 8] and want to find 3-student groups with an average of at least 4, you'd slide a window of size 3 across the array and check each group's average.
Key insight: Instead of calculating averages (which involves division), you can multiply the threshold by k and compare against the sum directly. This avoids floating-point precision issues!
Input & Output
Visualization
Time & Space Complexity
For each of (n-k+1) starting positions, we sum k elements
Only using variables to store current sum and counter
Constraints
- 1 β€ arr.length β€ 105
- 1 β€ arr[i] β€ 104
- 1 β€ k β€ arr.length
- 0 β€ threshold β€ 104
- All array elements are positive integers