FastPrepMinimum Appointment Cancellations with a Required Break

Minimum Appointment Cancellations with a Required Break

Maven Clinic logoMaven Clinic● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given same-day appointments as [startHHMM, endHHMM] pairs and a required nonnegative break in minutes. Two kept appointments are compatible when the later appointment starts at least breakMinutes minutes after the earlier appointment ends.

Cancel the minimum number of appointments so that all remaining appointments are compatible. Return the cancelled appointments in their original input order.

When several maximum-size compatible schedules exist, keep the schedule produced by considering appointments in increasing end time, then increasing start time, then original input order.

Function

cancelAppointments(intervals: int[][], breakMinutes: int) → int[][]

Examples

Example 1

intervals = [[1000,1030],[1005,1010],[1115,1120]]breakMinutes = 5return = [[1000,1030]]

Keeping the appointment ending at 10:10 leaves room for the 11:15 appointment, so only the longer 10:00 appointment is cancelled.

Example 2

intervals = [[1400,1459],[1500,1530]]breakMinutes = 5return = [[1500,1530]]

The second appointment starts one minute after the first ends, which is less than the required five-minute break.

Example 3

intervals = [[900,930],[935,1000],[1010,1040]]breakMinutes = 5return = []

Every consecutive gap meets or exceeds five minutes, so nothing is cancelled.

Constraints

  • 0 <= intervals.length <= 100000.
  • Every time is a valid same-day 24-hour HHMM value.
  • Each appointment satisfies startHHMM < endHHMM after conversion to minutes.
  • 0 <= breakMinutes <= 1440.
  • No appointment crosses midnight.

More Maven Clinic problems

See Maven Clinic hiring insights
public int[][] cancelAppointments(int[][] intervals, int breakMinutes) {
    // Write your code here.
}
intervals[[1000,1030],[1005,1010],[1115,1120]]
breakMinutes5
expected[[1000,1030]]
Checking account…