Find Available Meeting Slots
At Apple, efficient scheduling is crucial for collaboration across teams and time zones. Imagine you're building a feature for a new internal scheduling tool that helps employees find optimal meeting times. This problem asks you to identify all available time slots for a meeting of a specified duration, given an employee's existing busy schedule and their defined working hours. The goal is to maximize productivity by quickly pinpointing when an employee can realistically attend a new meeting.
You are tasked with implementing a function that calculates an employee's free time slots within their working hours, considering their existing commitments.
workingHours that are not covered by the consolidated busy intervals. These are the potential free slots.meetingDuration minutes.HHMM format as the input.The function signature is findAvailableSlots(busyIntervals: number[][], meetingDuration: number, workingHours: number[]): number[][].
busyIntervals: An array of [start, end] pairs, where start and end are integers representing times in HHMM format (e.g., 900 for 9:00 AM, 1730 for 5:30 PM). Each interval [start, end] signifies that the employee is busy from start up to, but not including, end. These intervals are not necessarily sorted and may overlap.meetingDuration: An integer representing the required duration of the meeting in minutes.workingHours: A [start, end] pair, also in HHMM format, defining the employee's total available working period for the day. Similar to busyIntervals, [start, end] means from start up to, but not including, end.The function should return an array of [start, end] pairs, representing the available time slots in HHMM format, sorted by their start times. Each returned slot must be at least meetingDuration minutes long.
HHMM format. For example, 100 means 1:00 AM, 930 means 9:30 AM, 1700 means 5:00 PM. Assume valid 24-hour format where HH is 00-23 and MM is 00-59.[start, end] means the period starting exactly at start and ending just before end. For example, [900, 1000] represents the hour from 9:00 AM to 9:59 AM.busyIntervals: If busyIntervals is empty, the entire workingHours period (if long enough) is considered available.[].Examples
Example 1
Input:
busyIntervals = [[900, 1030], [1100, 1200], [1000, 1030]], meetingDuration = 30, workingHours = [800, 1800]
Output:
[[800, 900], [1030, 1100], [1200, 1800]]
Note:
[[900, 1030], [1000, 1030], [1100, 1200]][[900, 1030], [1100, 1200]][800, 1800] (8:00 AM to 6:00 PM)[800, 900] (duration: 60 minutes)[1030, 1100] (duration: 30 minutes)[1200, 1800] (duration: 360 minutes)Example 2
Input:
busyIntervals = [[900, 1000], [1000, 1100]], meetingDuration = 60, workingHours = [800, 1200]
Output:
[[800, 900], [1100, 1200]]
Note:
[[900, 1000], [1000, 1100]][[900, 1100]] (contiguous intervals merge)[800, 1200][800, 900] (duration: 60 minutes)[1100, 1200] (duration: 60 minutes)meetingDuration.Example 3
Input:
busyIntervals = [[900, 1700]], meetingDuration = 120, workingHours = [800, 1800]
Output:
[]
Note:
[[900, 1700]][800, 1800][800, 900] (duration: 60 minutes)[1700, 1800] (duration: 60 minutes)meetingDuration of 120 minutes. Therefore, no available slots.Constraints
0 <= busyIntervals.length <= 100busyIntervals[i].length === 20 <= busyIntervals[i][0] < busyIntervals[i][1] <= 24001 <= meetingDuration <= 1440 (a full day)workingHours.length === 20 <= workingHours[0] < workingHours[1] <= 2400HHMM format.workingHours[0] will always be less than workingHours[1].busyIntervals are within a single day.Loading editor...