Time Slot Scheduler - Problem

You are building a meeting scheduler application. Given a list of meeting time slots represented as [start, end] intervals, you need to:

1. Find all free time slots during a standard workday (9 AM to 5 PM, represented as [9, 17])

2. Detect any double-bookings (overlapping meetings)

Return a result object containing:

  • freeSlots: Array of [start, end] intervals representing free time
  • conflicts: Array of [start, end] intervals representing overlapping meetings

Note: All times are represented as integers (9 = 9 AM, 17 = 5 PM, etc.)

Input & Output

Example 1 — Basic Scheduling
$ Input: meetings = [[10,12],[11,13],[14,15]]
Output: {"freeSlots":[[9,10],[13,14],[15,17]],"conflicts":[[11,12]]}
💡 Note: Meeting [11,13] overlaps with [10,12] from 11-12. Free time exists before 10, between 13-14, and after 15.
Example 2 — No Conflicts
$ Input: meetings = [[9,10],[11,12],[14,16]]
Output: {"freeSlots":[[10,11],[12,14],[16,17]],"conflicts":[]}
💡 Note: All meetings are separate with no overlaps. Free slots exist in the gaps between meetings.
Example 3 — Multiple Conflicts
$ Input: meetings = [[10,14],[11,13],[12,15]]
Output: {"freeSlots":[[9,10],[15,17]],"conflicts":[[11,13],[12,14]]}
💡 Note: Three-way overlap: [11,13] conflicts with [10,14], and [12,15] conflicts with both previous meetings.

Constraints

  • 0 ≤ meetings.length ≤ 100
  • meetings[i].length == 2
  • 0 ≤ starti < endi ≤ 24
  • Workday is defined as [9, 17] (9 AM to 5 PM)

Visualization

Tap to expand
INPUTALGORITHMRESULTMeeting Schedule[[10,12],[11,13],[14,15]]Workday: 9 AM - 5 PM9 10 11 12 13 14 15 16 17Timeline visualization1. Sort by start time2. Detect overlaps3. Find gaps4. Return resultsProcessing:[10,12] → [11,13] overlap!Conflict: [11,12]Free: [9,10], [13,14], [15,17]Scheduler OutputFree Slots:[[9,10],[13,14],[15,17]]Conflicts:[[11,12]]✓ 3 free time slots found✓ 1 booking conflict detected✓ Ready for scheduling!Key Insight:Sorting meetings chronologically allows detection of overlaps and free time in a single pass,making scheduling conflicts obvious and gap identification efficient.TutorialsPoint - Time Slot Scheduler | Sort-First Approach
Asked in
Google 42 Amazon 38 Microsoft 35 Meta 28
28.5K Views
Medium Frequency
~25 min Avg. Time
894 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen