Z21

Number of Sub-arrays of Size K and Average Greater than Threshold

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

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) -> int

Input & 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^4

Example Execution Walkthrough

arr = [2,2,2,2,5,5,5,8], k = 3, threshold = 4
result: 3

Example Test Scenarios (3)

Example 1
Input:[[2,2,2,2,5,5,5,8],3,4]
Expected Output:3
Example 2
Input:[[11,13,17,23,29,31,7,5,2,3],3,5]
Expected Output:6
Example 3
Input:[[7,7,7,7,7,7,7],7,7]
Expected Output:1
Loading Python Editor...
Input Parameters
[
  [
    2,
    2,
    2,
    2,
    5,
    5,
    5,
    8
  ],
  3,
  4
]
Expected Output
3