Employee Free Time - Problem
Find Common Free Time for All Employees
Imagine you're managing a team and need to schedule a meeting that works for everyone. You have each employee's working schedule as a list of time intervals, and you need to find all the time slots when everyone is free.
Given a list
Goal: Find time slots when ALL employees are simultaneously free
Input: List of employee schedules (each schedule is a list of intervals)
Output: List of intervals representing common free time
Note: Only return intervals with positive length (exclude zero-length intervals like [5,5])
Imagine you're managing a team and need to schedule a meeting that works for everyone. You have each employee's working schedule as a list of time intervals, and you need to find all the time slots when everyone is free.
Given a list
schedule where schedule[i] represents the working intervals for employee i, return all the common free time intervals for all employees. Each employee's intervals are non-overlapping and sorted.Goal: Find time slots when ALL employees are simultaneously free
Input: List of employee schedules (each schedule is a list of intervals)
Output: List of intervals representing common free time
Note: Only return intervals with positive length (exclude zero-length intervals like [5,5])
Input & Output
example_1.py โ Basic Case
$
Input:
schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]
โบ
Output:
[[5,6],[7,9]]
๐ก Note:
Employee 1 works [1,3] and [6,7]. Employee 2 works [2,4]. Employee 3 works [2,5] and [9,12]. The common free times are [5,6] (between 5-6, no one is working) and [7,9] (between 7-9, no one is working).
example_2.py โ Overlapping Schedules
$
Input:
schedule = [[[1,3],[4,6]],[[2,5],[7,9]]]
โบ
Output:
[[6,7]]
๐ก Note:
Employee 1 works [1,3] and [4,6]. Employee 2 works [2,5] and [7,9]. The merged busy time is [1,6] and [7,9], so the only free time is [6,7].
example_3.py โ No Free Time
$
Input:
schedule = [[[1,10]],[[2,6],[8,10]],[[1,9]]]
โบ
Output:
[]
๐ก Note:
Employee 1 works [1,10], Employee 2 works [2,6] and [8,10], Employee 3 works [1,9]. When we merge all intervals, we get [1,10] with no gaps, so there's no common free time.
Constraints
- 1 โค schedule.length, schedule[i].length โค 50
- 0 โค schedule[i][j].start < schedule[i][j].end โค 108
- Each employee's intervals are non-overlapping and sorted
- Only return positive-length intervals (exclude zero-length like [5,5])
Visualization
Tap to expand
Understanding the Visualization
1
Collect All Busy Times
Gather all working intervals from every employee's schedule
2
Sort Chronologically
Arrange all intervals by their start time to process them in order
3
Merge Overlapping Periods
Combine overlapping work periods to get consolidated busy times
4
Find the Gaps
The spaces between merged busy periods are your meeting opportunities
Key Takeaway
๐ฏ Key Insight: Free time exists in the gaps between merged busy intervals. By combining all schedules and finding the holes, we discover when everyone is simultaneously available.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code