Learn DSA
Depth-First Search
Greedy Algorithms
Intervals
Employee Free Time
hard
DESCRIPTION (credit Leetcode.com)
Write a function to find the common free time for all employees from a list called schedule. Each employee's schedule is represented by a list of non-overlapping intervals sorted by start times. The function should return a list of finite, non-zero length intervals where all employees are free, also sorted in order.
Input:
Output:
Explanation: The three employees collectively have only one common free time interval, which is from 5 to 6.
Explanation
Phase 1
employee free time
0 / 1
Phase 2
merge intervals
0 / 8
Phase 3
merge
0 / 4
Test Your Knowledge
Login to take the complexity quiz and track your progress
Complexity Analysis
Time Complexity: O(n * logn) where n
is the number of intervals. The time complexity is dominated by the sorting step.
Space Complexity: O(n) where n
is the number of intervals. We need space for the free_times
output array.
Solution
employee free time
0 / 14
Login to track your progress
Your account is free and you can post anonymously if you choose.