Quick Overview

Find fixed-duration deployment windows on a repeating UTC week by translating local allow and freeze rules, respecting lead time, wraparound intervals, and a three-week search horizon.

Find Weekly Deployment Windows Across Time Zones

Company: Stripe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Online Assessment

## Problem A week is a repeating timeline of `10080` minutes. Teams define local-time intervals that either allow or freeze deployments, together with fixed UTC offsets. Find the first `k` non-overlapping UTC deployment windows after a lead-time boundary. ## Function Contract Implement `deployment_windows(utc_now, lead_time, min_duration, k, rules)` and return half-open absolute UTC intervals `[start, end]`. Each rule is `[kind, local_start, local_end, offset]`. ## Rules - `kind` is `"ALLOW"` or `"FREEZE"`; local intervals are half-open and may wrap across the weekly boundary. - At absolute UTC minute `u`, a rule is active when `(u + offset) mod 10080` lies in its local interval. - A minute is deployable when at least one `ALLOW` rule is active and no `FREEZE` rule is active. - No returned start may be earlier than `utc_now + lead_time`, and every window has exactly `min_duration` consecutive deployable minutes. - Split a longer deployable span into adjacent windows of length `min_duration`; discard a trailing fragment that is too short. - Search the half-open horizon from the earliest start through three complete weeks later, and return fewer than `k` windows if necessary. ## Constraints - `0 <= utc_now, lead_time <= 10^9`. - `1 <= min_duration <= 10080`. - `1 <= k <= 10000`. - `1 <= len(rules) <= 10000`. - Offsets are integer minutes in `[-1440, 1440]`; local endpoints are in `[0, 10080]`. ## Examples ```text utc_now = 10070 lead_time = 20 min_duration = 30 k = 2 rules = [["ALLOW", 0, 120, 60]] output = [[10090,10120],[20100,20130]] ``` The lead-time boundary is `10090`. With the positive offset, the current deployable span is `[10090, 10140)`, which contains one 30-minute window and a 20-minute trailing fragment. The fragment is discarded. The underlying weekly allow interval next recurs as the UTC span `[20100, 20220)`, whose first 30-minute window is `[20100, 20130)`, providing the second requested window.

Quick Answer: Find fixed-duration deployment windows on a repeating UTC week by translating local allow and freeze rules, respecting lead time, wraparound intervals, and a three-week search horizon.

## Problem A week is a repeating timeline of `10080` minutes. Teams define local-time intervals that either allow or freeze deployments, together with fixed UTC offsets. Find the first `k` non-overlapping UTC deployment windows after a lead-time boundary. ## Function Contract Implement `deployment_windows(utc_now, lead_time, min_duration, k, rules)` and return half-open absolute UTC intervals `[start, end]`. Each rule is `[kind, local_start, local_end, offset]`. ## Rules - `kind` is `"ALLOW"` or `"FREEZE"`; local intervals are half-open and may wrap across the weekly boundary. - At absolute UTC minute `u`, a rule is active when `(u + offset) mod 10080` lies in its local interval. - A minute is deployable when at least one `ALLOW` rule is active and no `FREEZE` rule is active. - No returned start may be earlier than `utc_now + lead_time`, and every window has exactly `min_duration` consecutive deployable minutes. - Split a longer deployable span into adjacent windows of length `min_duration`; discard a trailing fragment that is too short. - Search the half-open horizon from the earliest start through three complete weeks later, and return fewer than `k` windows if necessary. ## Constraints - `0 <= utc_now, lead_time <= 10^9`. - `1 <= min_duration <= 10080`. - `1 <= k <= 10000`. - `1 <= len(rules) <= 10000`. - Offsets are integer minutes in `[-1440, 1440]`; local endpoints are in `[0, 10080]`. ## Examples ```text utc_now = 10070 lead_time = 20 min_duration = 30 k = 2 rules = [["ALLOW", 0, 120, 60]] output = [[10090,10120],[20100,20130]] ``` The lead-time boundary is `10090`. With the positive offset, the current deployable span is `[10090, 10140)`, which contains one 30-minute window and a 20-minute trailing fragment. The fragment is discarded. The underlying weekly allow interval next recurs as the UTC span `[20100, 20220)`, whose first 30-minute window is `[20100, 20130)`, providing the second requested window.

Constraints

  • 0 <= utc_now, lead_time <= 10^9.
  • 1 <= min_duration <= 10080.
  • 1 <= k <= 10000.
  • 1 <= len(rules) <= 10000.
  • Each rule is [kind, local_start, local_end, offset], where kind is ALLOW or FREEZE.
  • Offsets are integer minutes in [-1440, 1440]; local endpoints are in [0, 10080].
  • Local and returned intervals are half-open; local intervals may wrap across the weekly boundary.
  • The search horizon is [utc_now + lead_time, utc_now + lead_time + 3 * 10080).

Examples

Input: (10070, 20, 30, 2, [['ALLOW', 0, 120, 60]])

Expected Output: [[10090, 10120], [20100, 20130]]

Explanation: Sample 1 (the corrected source example): the lead boundary leaves one full 30-minute window in the current span, and the second comes from the next weekly recurrence.

Input: (0, 0, 60, 3, [['ALLOW', 0, 300, 0], ['FREEZE', 120, 180, 0]])

Expected Output: [[0, 60], [60, 120], [180, 240]]

Explanation: Sample 2: the freeze splits one allow interval; windows are emitted in UTC order and stop after the third.

Hints

  1. Rules repeat every 10080 minutes, so reason about coverage within one week before mapping it onto the bounded absolute horizon.
  2. Half-open wrap points, the lead-time boundary, and trailing fragments shorter than min_duration all affect which windows are returned.

Loading coding console...