Longest K-Concurrent Outage Period
Postman relies on highly available services. When multiple services experience outages simultaneously, it can lead to critical system failures. This problem asks you to identify the longest continuous time window during which at least k distinct services were concurrently unavailable. This is crucial for understanding the impact of cascading failures and for post-incident analysis.
Implement the function findLongestKOverlapPeriod that takes a list of service outage intervals and an integer k, and returns the length of the longest time period where at least k services were simultaneously experiencing an outage.
outages: An array of number[] representing service outage intervals. Each inner array [start, end] denotes an outage from start time to end time (inclusive of start, exclusive of end). start < end is guaranteed.k: A positive integer representing the minimum number of concurrent outages required.Returns: A number representing the length of the longest period where at least k services were simultaneously down. If no such period exists, return 0.
[start, end] means the service is down for the duration [start, end). The time end itself is when the service becomes available again. The length of such an interval is end - start.k=1, you're looking for the longest single outage period (which might be a merged one if multiple outages form a continuous block).Examples
Example 1
Input:
outages = [[1, 5], [3, 7], [2, 6], [8, 10], [9, 12]], k = 2
Output:
4
Note:
Intervals: [1,5), [2,6), [3,7), [8,10), [9,12).
Example 2
Input:
outages = [[10, 20], [15, 25], [30, 40]], k = 3
Output:
0
Note:
Even though outages exist, at no point do 3 or more services concurrently experience an outage. The maximum concurrent outages is 2 (between time 15 and 20).
Example 3
Input:
outages = [[1, 10], [1, 5], [6, 10]], k = 1
Output:
9
Note:
Intervals: [1,10), [1,5), [6,10).
Constraints
0 <= outages.length <= 10^5outage interval [start, end] will have 0 <= start < end <= 10^9.1 <= k <= outages.length (If outages.length is 0, k will be ignored, and the function should return 0).outages array may not be sorted.start >= end). Assume valid input as per constraints.k=1, intervals of zero length (e.g., [5,5], though constrained to start < end), or no periods meeting the k criteria.outages.length).Loading editor...