Minimum Appointment Cancellations with a Required Break
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 < endHHMMafter conversion to minutes. 0 <= breakMinutes <= 1440.- No appointment crosses midnight.