Z21
Number of Sub-arrays of Size K and Average Greater than Threshold
Problem Statement & Objective
Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k and average greater than or equal to threshold.
Function Signature (Python)
num_subarrays_above_threshold(nums: list[int], k: int, threshold: int) -> intInput & Output Contract
Output Rule:Count integer of matching subarrays.
System Constraints
1 <= arr.length <= 10^5
1 <= k <= arr.length
0 <= arr[i] <= 10^4
0 <= threshold <= 10^4Example Execution Walkthrough
arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
result: 3Example Test Scenarios (3)
Example 1
Input:
[[2,2,2,2,5,5,5,8],3,4]Expected Output:
3Example 2
Input:
[[11,13,17,23,29,31,7,5,2,3],3,5]Expected Output:
6Example 3
Input:
[[7,7,7,7,7,7,7],7,7]Expected Output:
1