Practice/Netflix/Error Rate Monitor
Error Rate Monitor
CodingMust
Problem Overview
You are monitoring a system's error rates over time. Given an array errorRates where errorRates[i] represents the error rate at time i, determine if the system is healthy at a specific time point.
The system is considered healthy if ALL error rates within a time window are strictly below the given threshold (not equal to or above).
The time window is defined as [timePoint - timeRange, timePoint + timeRange] (inclusive). Only consider valid indices within the array bounds.
This is a straightforward array range query problem that tests boundary handling and comparison logic.
Example 1
`
errorRates = [1, 3, 2, 5, 4, 2, 1]
timePoint = 3
timeRange = 2
threshold = 6
Window: [3 - 2, 3 + 2] = [1, 5]
Indices 1 to 5 inclusive
Values: [3, 2, 5, 4, 2]
All values < 6? Yes
Output: true
`
Example 2
`
errorRates = [1, 3, 2, 5, 4, 2, 1]
timePoint = 3
timeRange = 2
threshold = 4
Window: [1, 5]
Values: [3, 2, 5, 4, 2]
All values < 4? No (5 and 4 are not strictly below 4)
Output: false
`
Example 3
`
errorRates = [1, 2, 3]
timePoint = 0
timeRange = 1
threshold = 5
Window: [0 - 1, 0 + 1] = [-1, 1]
Valid indices after clipping: [0, 1]
Values: [1, 2]
All values < 5? Yes
Output: true
`
Requirements
- Handle arrays up to length 10^5 efficiently
- Error rates can be from 0 to 10^4
- Properly clip the window to array bounds
- Use strict inequality (value must be strictly less than threshold)
- The threshold value itself is not acceptable
Clarification Questions to Ask
- Should we handle negative timePoint or timeRange values?
- Is it guaranteed that timePoint is a valid index in the array?
- What should we return for an empty window (though this shouldn't happen given constraints)?