You have a list of integers errors, where each entry records how many errors a service logged during a specific one‑hour window. You also have an SLO (service level objective) configuration with three parameters:
threshold – the maximum number of errors allowed in a single hour.duration – the length of a sliding monitoring window, measured in consecutive hours.percent – the minimum fraction of hours inside that window during which the error count must exceed the threshold for an alert to fire.In other words, an alert is raised only when the error count stays above the threshold for at least this portion of the window.
Write a function that scans the errors list and returns the total number of alerts that would be triggered. For every contiguous window of size duration, compute the proportion of hours whose error value is strictly greater than threshold. If that proportion is greater than or equal to percent, that window counts as one alert.
Constraints:
threshold is between 0 and 10<sup>4</sup>.duration is at least 1 and at most the length of the errors list.percent is a floating‑point number in the range [0.0, 1.0].Example 1:
errors = [1, 5, 7, 3, 6, 8, 2], threshold = 5, duration = 3, percent = 0.66
3
Alerts are triggered for the windows [7, 3, 6], [3, 6, 8], and [6, 8, 2]. Here is the reasoning: Window [1, 5, 7]: only 7 exceeds the threshold. Ratio = 1/3 ≈ 0.33 < 0.66 → no alert. Window [5, 7, 3]: only 7 exceeds the threshold → no alert. Window [7, 3, 6]: both 7 and 6 exceed the threshold. Ratio = 2/3 ≈ 0.66 ≥ 0.66 → alert. Window [3, 6, 8]: 6 and 8 exceed 5 → alert. Window [6, 8, 2]: 6 and 8 exceed 5 → alert.
Example 2:
errors = [1, 2, 3, 1, 2, 3], threshold = 5, duration = 3, percent = 0.5
0
Example 3:
errors = [10, 10, 10, 10, 10], threshold = 5, duration = 2, percent = 0.5
4