Max Scheduled Maintenance Slots
Apple's content delivery network (CDN) needs to efficiently schedule maintenance windows for its global server infrastructure. Each server has specific time slots when it's available for maintenance. To minimize disruption and ensure critical updates are applied, we need to select the maximum number of non-overlapping maintenance slots, with an additional constraint: each chosen slot must meet a minimum required duration to be effective.
Implement a function maxScheduledMaintenanceSlots that takes a list of available maintenance time slots and a minimum required duration. Your function should return the maximum number of non-overlapping maintenance slots that can be scheduled, where each selected slot has a duration equal to or greater than the specified minimum.
The function maxScheduledMaintenanceSlots takes two arguments:
intervals: An array of arrays, where each inner array [start, end] represents an available maintenance time slot. start and end are integers representing timestamps. start < end is guaranteed.minDuration: An integer representing the minimum required duration for a maintenance slot to be considered valid.The function should return an integer, representing the maximum number of non-overlapping maintenance slots that satisfy the minDuration constraint.
intervals is empty, return 0.minDuration is non-positive, treat it as 1 for filtering purposes.[start, end] are inclusive of start and exclusive of end. The duration of an interval [start, end] is end - start.[a, b] and [c, d] are non-overlapping if b <= c or d <= a.Examples
Example 1
Input:
intervals = [[1, 4], [2, 5], [7, 9], [3, 8]], minDuration = 2
Output:
2
Note:
Example 2
Input:
intervals = [[1, 2], [2, 3], [3, 4]], minDuration = 1
Output:
3
Note:
Example 3
Input:
intervals = [[1, 5], [2, 3], [4, 6]], minDuration = 3
Output:
1
Note:
Constraints
0 <= intervals.length <= 10^5intervals[i].length == 20 <= start < end <= 10^9 for each [start, end] in intervals.1 <= minDuration <= 10^9 (after accounting for non-positive minDuration as 1).intervals are not necessarily sorted.Loading editor...