Find Weekly Deployment Windows Across Time Zones
StripeSoftware Engineer · Online AssessmentLast updated
Determine the first k non-overlapping deployment windows across a 3-week search horizon by mapping weekly recurring local allow and freeze rules into a repeating UTC timeline.
Problem Statement
Global engineering teams operate across different time zones with specific deployment policies. Some policies define when deployments are permitted (ALLOW), while others enforce quiet periods or code freezes (FREEZE). All policies recur weekly on local schedules.
You are tasked with finding the first k non-overlapping deployment windows of length duration minutes that satisfy all policies.
A repeating UTC week consists of 10,080 minutes (7 * 24 * 60), indexed from 0 (Sunday 00:00 UTC) to 10079 (Saturday 23:59 UTC).
Each rule is defined with:
rule_type:"ALLOW"or"FREEZE"day: Day of week (0= Sunday,1= Monday, ...,6= Saturday)start_minute: Minute within the day (0to1439, inclusive)end_minute: Minute within the day (1to1440, exclusive boundary, where1440is midnight of the next day)tz_offset: Time zone offset from UTC in minutes (Local Time = UTC +tz_offset)
A UTC minute m (0 <= m < 10080) is considered deployable if and only if:
- It falls within at least one active
ALLOWrule (after translating the rule to UTC). - It does not fall within any active
FREEZErule (after translating the rule to UTC).
A deployment window of size duration starting at absolute UTC minute T is valid if every minute in [T, T + duration) is deployable (i.e., t % 10080 is deployable for all t in the window).
Find and return the start times of the first k valid, non-overlapping deployment windows. Search strictly within the range [current_utc_minute + lead_time, current_utc_minute + 3 * 10080).
Function Signature
def find_deployment_windows(
rules: list[dict],
duration: int,
lead_time: int,
current_utc_minute: int,
k: int
) -> list[int]:
pass
Input & Output Format
rules: List of dicts, each with keys'type'("ALLOW"|"FREEZE"),'day'(int),'start_minute'(int),'end_minute'(int), and'tz_offset'(int).- Return a list of up to
kintegers representing the starting absolute UTC minutes (from week 0, minute 0) in ascending order. If fewer thankwindows exist within the 3-week search horizon, return all available windows.
Constraints
1 <= duration <= 14400 <= lead_time <= 100800 <= current_utc_minute < 100801 <= k <= 501 <= len(rules) <= 200-720 <= tz_offset <= 840
Examples
Example 1
rules = [
{"type": "ALLOW", "day": 0, "start_minute": 120, "end_minute": 300, "tz_offset": 0},
{"type": "FREEZE", "day": 0, "start_minute": 180, "end_minute": 200, "tz_offset": 0}
]
duration = 60
lead_time = 10
current_utc_minute = 100
k = 2
# Output: [200, 10280]
Explanation: Allowed UTC range is [120, 180) and [200, 300). Earliest search start is 100 + 10 = 110. Window [130, 190) overlaps the freeze [180, 200). The first valid 60-minute window is [200, 260). The next non-overlapping window on week 0 would need to start at >= 260, but the allowed window ends at 300 (insufficient length). The second window occurs in week 1 at minute 10080 + 200 = 10280.
Hints
Hint 1
Convert each local interval [start, end) into weekly absolute UTC minutes [0, 10080) by accounting for day, minute offset, and modulo wraparound.
Hint 2
Precompute a boolean array of size 10080 indicating whether each minute of the base UTC week is deployable (allowed and not frozen).
Hint 3
Slide a window across the 3-week horizon (using prefix sums or a two-pointer approach over the 10080-minute repeating pattern) to find valid consecutive deployable minutes without re-checking individual rules.
Follow-up questions
- How would you optimize this if duration and lead time could span several weeks, and rules had non-weekly recurrence (e.g., month-end freezes or one-off incidents)?
- How can you handle interval arithmetic efficiently if the timeline granularity is seconds or milliseconds instead of minutes?
- If multiple candidate windows have varying risk scores based on historical traffic patterns, how would you select the top k optimal deployment windows instead of just the earliest ones?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.