← 返回 stripe 的题目列表Weekly Deployment Window Scheduler
类型:online_judge
Problem: Weekly Deployment Window Scheduler
A week has 10080 minutes. A time is represented as the minute index within a week:
0 means Monday 00:00
60 means Monday 01:00
10079 means Sunday 23:59
All intervals are half-open intervals [start, end).
There are two kinds of windows:
allowed: deployment is allowed during this window
freeze: deployment is forbidden during this window
A final deployable time must satisfy both conditions:
It is inside at least one allowed interval.
It is not inside any freeze interval.
In other words:
deployable windows = union of allowed intervals - union of freeze intervals
Adjacent deployable intervals should be merged, and the result should be sorted by start time.
Input Format
The first line is the mode:
part1
or:
part2
Part 1
Each following line has the format:
start,end,type
where:
0 <= start <= end <= 10080
type is either allowed or freeze
The interval is [start, end)
If start == end, the interval is empty and can be ignored.
Return all deployable intervals within the week.
Part 2
The second line is a configuration line:
utc_now,lead_time_minutes,min_continuous_minutes,k
where:
utc_now: current UTC time, represented as a minute index within a week
lead_time_minutes: deployment lead time; the earliest deployment start time is utc_now + lead_time_minutes
min_continuous_minutes: minimum required continuous deployment duration
k: return at most the next k deployable windows
Each following window line has the format:
start,end,type,timezone_offset_minutes
where:
start and end are local minute indices within a week
timezone_offset_minutes is the local timezone offset from UTC
Conversion formula:
UTC = local_time - timezone_offset_minutes
After conversion, take modulo 10080. If the converted interval crosses the week boundary, split it into two intervals. For example, [1380, 120) becomes [1380, 10080) and [0, 120).
For Part 2, the final returned windows must also satisfy:
The start time is not earlier than utc_now + lead_time_minutes.
The continuous length is at least min_continuous_minutes.
Results are sorted by UTC start time.
Return at most k windows.
If a deployable window overlaps the earliest start time, it can be trimmed. For example, [1000, 1100) with earliest start time 1050 becomes [1050, 1100).
Output Format
Output one deployable interval per line:
start end
If there is no deployable interval, output nothing.
Example 1: Part 1
Input:
part1
540,600,allowed
570,585,freeze
Output:
540 570
585 600
Explanation:
allowed: [540, 600)
freeze: [570, 585)
Result: [540, 570) and [585, 600).
Example 2: Part 2
Input:
part2
1020,0,10,5
540,600,allowed,-480
550,565,freeze,-480
Output:
1020 1030
1045 1080
Explanation:
timezone_offset_minutes = -480, so:
UTC = local - (-480) = local + 480
After conversion:
allowed: [1020, 1080)
freeze: [1030, 1045)
After subtracting the freeze window:
[1020, 1030), length 10
[1045, 1080), length 35
Both satisfy the minimum continuous duration of 10 minutes.
Example
Input
part1
540,600,allowed
570,585,freeze
Output
540 570
585 600