Description
Company: Netflix
System Health Monitor
The Challenge
You need to check the safety levels of a system. You are given an array called errorRates. The value at errorRates[i] tells you the error rate at time i. Your job is to find out if the system is working correctly at a specific moment.
The system is considered healthy only if every error rate inside a specific time window is strictly smaller than a threshold.
The time window starts at timePoint - timeRange and ends at timePoint + timeRange. You must check the numbers inclusive of these start and end points. Be sure to only check valid spots in the array (do not go before the beginning or past the end of the array).
Return true if the system is healthy. Return false if it is not.
Sample Cases
Case 1:
Input: errorRates = [1, 3, 2, 5, 4, 2, 1], timePoint = 3, timeRange = 2, threshold = 6
Output: true
Explanation:
The calculated window is from index 1 to 5. The values in this range are [3, 2, 5, 4, 2]. Every number here is smaller than 6, so the system is healthy.
Case 2:
Input: errorRates = [1, 3, 2, 5, 4, 2, 1], timePoint = 3, timeRange = 2, threshold = 4
Output: false
Explanation:
The window again covers indices 1 to 5 with values [3, 2, 5, 4, 2]. The value 5 is NOT smaller than the threshold of 4. Because of this, the system is unhealthy.
Case 3:
Input: errorRates = [1, 2, 3], timePoint = 0, timeRange = 1, threshold = 5
Output: true
Explanation:
The math says the window should be [-1, 1]. However, index -1 does not exist. We only check the valid indices [0, 1]. The values are [1, 2]. Both are smaller than 5.
Input Limits
1 <= errorRates.length <= 10^5 0 <= errorRates[i] <= 10^4 0 <= timePoint < errorRates.length 0 <= timeRange <= errorRates.length 1 <= threshold <= 10^4