Problem · Array

Threshold Alerts

EasyGoldman SachsINTERNFULLTIMEOA

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𓂃 𓈒𓏸

Examples
01 · Example 1
precedingMinutes = 3
alertThreshold = 10
numCalls = [0, 11, 10, 10, 7]
return = 1
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.
02 · Example 2
precedingMinutes = 3
alertThreshold = 5
numCalls = [0, 11, 10, 10, 7]
return = 3
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
  • 1 ≤ precedingMinutes ≤ n
  • 1 ≤ alertThreshold ≤ 105
  • 1 <= n <= 105
  • 0 <= numCalls[i] <= 105
More Goldman Sachs problems
drafts saved locally
public int numberOfAlerts(int precedingMinutes, int alertThreshold, int[] numCalls) {
  // write your code here
}
precedingMinutes3
alertThreshold10
numCalls[0, 11, 10, 10, 7]
expected1
sign in to submit