FastPrepFastPrep
Problem Brief

Threshold Alerts

INTERNFULLTIMEOA

A compliance system monitors incoming and outbound calls. It sends an alert whenever the average number of calls over a trailing number of minutes exceeds a threshold. If the number of trailing minutes to consider, precedingMinutes = 5, at time T, take the average the call volumes for times T-5(T-1), T-5(2)...T-5(5).

No alerts are sent until at least T = 3 because there are not enough values to consider. When T = 3, the average calls = (2 + 2 + 2)/3 = 2. Additionally, average calls from T = 3 to T = 8 are 2, 2, 3, 4, 5, and 6. A total of two alerts are sent during the last two periods. Given the data as described, determine the number of alerts sent by the end of the timeframe.

Function Description

Complete the function numberOfAlerts in the editor.

numberOfAlerts has the following parameters:

  1. 1. int precedingMinutes: the trailing number of minutes to consider
  2. 2. int alertThreshold: the maximum number of calls allowed before triggering an alert
  3. 3. int numCalls[n]: numCalls[i] represents the number of calls made during the ith minute

Returns

int: the number of alerts sent over the timeframe

٩(ˊᗜˋ*)و ♡ Credit to Oso𓂃 𓈒𓏸

1Example 1

Input
precedingMinutes = 3, alertThreshold = 10, numCalls = [0, 11, 10, 10, 7]
Output
1
Explanation
An alert is sent at the end of three minutes since the average number of calls during the interval (11, 10, and 10) exceeds 10.

2Example 2

Input
precedingMinutes = 3, alertThreshold = 5, numCalls = [0, 11, 10, 10, 7]
Output
3
Explanation
An alert is sent at the ends of minutes 2, 3, and 4 since the average number of calls in the previous three minutes (0,11,10), (11,10,10), and (10, 10, 7) exceed 5.

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ precedingMinutes ≤ n
  • 1 ≤ alertThreshold ≤ 105
  • 1 <= n <= 105
  • 0 <= numCalls[i] <= 105
public int numberOfAlerts(int precedingMinutes, int alertThreshold, int[] numCalls) {
  // write your code here
}
Input

precedingMinutes

3

alertThreshold

10

numCalls

[0, 11, 10, 10, 7]

Output

1

Sign in to submit your solution.