Problem · Intervals

Deployment Window Scheduler

Learn this problem
HardStripeOA
See Stripe hiring insights

Problem statement

Implement scheduleDeploymentWindows for both modes described below. The value of part determines how to read inputCsv and which rules to apply.

Return the resulting deployment windows as [[start, end], ...], sorted by start time.

Common Rules

  • A week contains 10080 minutes. Minute 0 is Monday 00:00, and valid weekly minute positions range from 0 through 10079.
  • Every interval is half-open: [start, end).
  • An allowed interval permits deployment. A freeze interval prohibits deployment.

Part 1

When part is "part1", every row in inputCsv has this format:

start,end,type

Compute the union of all allowed intervals, then subtract the union of all freeze intervals. Allowed intervals may overlap, freeze intervals may overlap, and adjacent deployable intervals must be merged.

Part 2

When part is "part2", the first row in inputCsv contains the global settings:

utc_now,lead_time_minutes,min_continuous_minutes,k

Every remaining row describes a local-time interval:

start,end,type,timezone_offset_minutes

Process Part 2 in this order:

  1. Convert each local interval to UTC using UTC = local_time - timezone_offset_minutes.
  2. Normalize converted times modulo 10080. If a converted interval crosses the week boundary, split it into two weekly intervals.
  3. Compute deployable time using the Part 1 allowed-minus-freeze rules.
  4. Discard every portion before utc_now + lead_time_minutes.
  5. Keep only remaining intervals whose continuous length is at least min_continuous_minutes.
  6. Sort the intervals by UTC start time and return at most the first k intervals.

Function

scheduleDeploymentWindows(part: String, inputCsv: String[]) → int[][]

Examples

Example 1

part = "part1"inputCsv = ["540,600,allowed","570,585,freeze"]return = [[540,570],[585,600]]

Part 1. The freeze interval removes [570,585) from the allowed interval [540,600).

Example 2

part = "part2"inputCsv = ["1020,0,10,5","540,600,allowed,-480","550,565,freeze,-480"]return = [[1020,1030],[1045,1080]]

Part 2. The offset converts the allowed interval to [1020,1080) and the freeze interval to [1030,1045). Both remaining windows are at least 10 minutes long.

Constraints

  • Weekly minute values are normalized over a 10080-minute week.
  • All intervals are half-open.
  • Window rows use type allowed or freeze.

More Stripe problems

drafts saved locally
public int[][] scheduleDeploymentWindows(String part, String[] inputCsv) {
  // write your code here
}
part"part1"
inputCsv["540,600,allowed","570,585,freeze"]
expected[[540,570],[585,600]]
checking account