Minimum Appointment Cancellations with a Required Break
Updated
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.
More Maven Clinic interview questions
- Shortest Currency Conversion with Three-Decimal RatePHONE SCREEN · Seen Mar 2026
- Configurable Valid BracketsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2025
- Meeting Rooms IIPHONE SCREEN · Seen Aug 2025
- Possible BipartitionPHONE SCREEN · Seen Aug 2024
- Paginate Provider Listings with Per-Page DiversityONSITE INTERVIEW · Seen Apr 2026
- Longest Valid ParenthesesONSITE INTERVIEW · Seen Aug 2025
Similar questions at other companies
- Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions
- Maximum Compatible Time WindowsIBM · OAIBM interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Minimum Markers to Clear Line SegmentsHSBC · OAHSBC interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Minimum Removals for Non-Overlapping IntervalsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Most Disjoint Intervals From Starts and DurationsDocuSign · OADocuSign interview questions
- University Career FairRoblox · OARoblox interview questions