PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

Implement a weekly deployment-window scheduler that subtracts freeze periods from allowed time and supports repeating local schedules in UTC. Handle cyclic intervals, time-zone offsets, absolute lead-time horizons, cross-week merging, full-week windows, and minimum continuous duration without minute-by-minute scans.

  • medium
  • Stripe
  • Coding & Algorithms
  • Software Engineer

Schedule Weekly Deployment Windows

Company: Stripe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

# Schedule Weekly Deployment Windows The source reports a weekly deployment-window scheduler. The absolute-time horizon, cyclic `start == end` rule, and cross-week merge behavior below are deterministic practice clarifications where the report does not supply an exact contract. Implement a scheduler over a repeating UTC week. Let `W = 10080` minutes. All intervals are half-open. ```python def schedule_deployments(part: str, input_csv: list[str]) -> list[list[int]]: ... ``` `part` is exactly `"1"` or `"2"`. Input rows are syntactically valid CSV with base-10 integers. ## Part 1: Allowed Time Minus Freeze Time Every row is: ```text start,end,type ``` `type` is `allowed` or `freeze`, and `0 <= start < end <= W`. Compute the set covered by at least one allowed interval and no freeze interval. Return its maximal intervals as `[[start, end], ...]`, sorted by start. Merge touching output intervals. Freeze always wins. Example: ```text 540,600,allowed 570,585,freeze ``` returns `[[540, 570], [585, 600]]`. No allowed rows returns `[]`. `[0, W)` represents a full-week source interval. ## Part 2: Absolute Time and a Repeating Local Schedule The first row is: ```text utc_now,lead_time_minutes,min_continuous_minutes,k ``` `utc_now` is a nonnegative absolute UTC minute on an unbounded timeline, not a minute-of-week value. The other three values are nonnegative integers. Define: ```text earliest = utc_now + lead_time_minutes horizon = [earliest, earliest + W) ``` Search exactly that one-week horizon. Every remaining row is: ```text start,end,type,timezone_offset_minutes ``` Local endpoints lie in `[0, W)`. Each row denotes a cyclic weekly interval: - If `start == end`, it denotes the full local week. - Otherwise its duration is `(end - start) mod W`, in `1..W-1`, walking forward from `start` to `end`. The offset means `UTC = local - timezone_offset_minutes`. For a non-full interval, compute: ```text utc_start = (start - timezone_offset_minutes) mod W utc_end_unwrapped = utc_start + duration ``` Split at multiples of `W` to obtain canonical UTC-week pieces. A full-week local interval remains a full-week UTC interval. Union allowed pieces, union freeze pieces, and subtract freeze from allowed. Treat the resulting UTC schedule as repeating every `W` minutes. Expand enough neighboring occurrences to cover `horizon`, intersect with the horizon, and merge touching absolute intervals. In particular, canonical pieces ending at `W` and beginning at `0` are one continuous interval across a week boundary when their repeated occurrences touch. Discard empty intervals and any interval whose clipped length is less than `min_continuous_minutes`. Return the first at most `k` maximal qualifying intervals in chronological order, using absolute unwrapped endpoints. If `k == 0`, return `[]`. If the deployable schedule covers the full week continuously, the only horizon result is `[earliest, earliest + W]`, provided `k > 0` and `W >= min_continuous_minutes`. A full-week freeze removes all output. ## Constraints and Edge Cases - Part 2 offsets may be any integer; normalization is modulo `W`. - When `min_continuous_minutes == 0`, every nonempty clipped interval qualifies. - A lead time may cross any number of week boundaries because `utc_now` is absolute. - Output is maximal only within the requested horizon; clipping at either horizon boundary is expected. - Do not iterate minute by minute. Base running time on sorting, union, subtraction, and the number of interval endpoints. Test local and UTC wrap, `start == end`, lead times beyond one week, a cut through a window, cross-week adjacency, touching allowed and freeze endpoints, full-week allowed and freeze rows, `k == 0`, and an empty allowed set.

Quick Answer: Implement a weekly deployment-window scheduler that subtracts freeze periods from allowed time and supports repeating local schedules in UTC. Handle cyclic intervals, time-zone offsets, absolute lead-time horizons, cross-week merging, full-week windows, and minimum continuous duration without minute-by-minute scans.

For part 1, union weekly allowed intervals and subtract all freeze intervals. For part 2, normalize cyclic local intervals into a repeating UTC-week schedule, subtract freezes, expand it over one absolute-week horizon after the lead time, clip, merge, filter by minimum duration, and return at most k intervals.

Constraints

  • A week is 10,080 minutes and all intervals are half-open.
  • Part 1 endpoints satisfy 0 <= start < end <= 10,080.
  • In part 2 start == end denotes a full local week.
  • Freeze coverage always wins.
  • Do not iterate minute by minute.

Examples

Input: {'part':'1','input_csv':['540,600,allowed','570,585,freeze']}

Expected Output: [[540, 570], [585, 600]]

Explanation: Freeze splits an allowed window.

Input: {'part':'1','input_csv':['0,20,allowed','10,30,allowed','5,8,freeze','20,25,freeze']}

Expected Output: [[0, 5], [8, 20], [25, 30]]

Explanation: Allowed unions and multiple freezes are normalized.

Hints

  1. Build reusable interval union and subtraction helpers.
  2. Split cyclic UTC intervals at the week boundary, then expand neighboring week copies around the absolute horizon.
  3. Merge touching intervals after expansion so week-boundary pieces reconnect.
Last updated: Jul 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Assign Reviewers from Changed Files - Stripe (medium)
  • Generate Account Email Notifications - Stripe (medium)
  • Calculate Transaction Fees - Stripe (medium)
  • Build an Account Transfer Ledger - Stripe (medium)