The Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold problem asks you to count subarrays of exactly length k whose average is ≥ threshold. This is equivalent to counting fixed-size windows with sum ≥ k * threshold. This coding problem is a clean fixed-size sliding window application.
Goldman Sachs, Amazon, and LinkedIn ask this as a standard fixed-size sliding window problem. It validates the efficient sliding window pattern — maintain a running sum and slide the window one step at a time instead of recomputing the sum from scratch. The array and sliding window interview pattern is directly demonstrated.
Fixed-size sliding window. Compute the sum of the first k elements. Compare with k * threshold. Slide the window: for each subsequent position, add the new element and subtract the element leaving the window. Update count if window_sum >= k * threshold.
arr=[2,2,2,2,5,5,5,8], k=3, threshold=4. Required sum = 3*4=12.
Fixed-size sliding window is the pattern for all "subarray of size k with aggregate condition" problems. The template: compute initial window, then for each step: add arr[i] and subtract arr[i-k], check condition. Never recompute from scratch. Comparing sum >= k * threshold instead of avg >= threshold avoids floating-point division. Practice all sliding window variants: min, max, sum, product, count. This pattern is fundamental for Goldman Sachs and LinkedIn quantitative interviews.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| K Radius Subarray Averages | Medium | Solve | |
| Count Subarrays Where Max Element Appears at Least K Times | Medium | Solve | |
| Grumpy Bookstore Owner | Medium | Solve | |
| Minimum Swaps to Group All 1's Together II | Medium | Solve | |
| Alternating Groups II | Medium | Solve |