A compliance monitor tracks the number of inbound and outbound calls. For every time point T, compute the mean call count across the most recent precedingMinutes entries: from T - (precedingMinutes - 1) up to and including T. Raise an alert whenever that mean is strictly above alertThreshold. Since a complete window is unavailable earlier, do not issue any alert before T = precedingMinutes.
Return how many alerts occur across the entire input.
public static int numberOfAlerts(int[] numCalls, int alertThreshold, int precedingMinutes)
n = 8
numCalls = [1, 3, 3, 3, 6, 6, 6, 9]
alertThreshold = 5
precedingMinutes = 3
Alerts cannot occur before T = 3. For T = 3 through T = 8, the rolling averages are
7/3, 3, 4, 5, 6, 7.
The values that are strictly above 5 are 6 and 7, so the result is 2 alerts.