LeetCode #759: Employee Free Time, Merge Every Schedule Interval
Brute To Best
0:00 / 0:00
LeetCode #759: Employee Free Time, Merge Every Schedule Interval
3 просмотра · 7 ч назад
Brute To Best
101 подписчик
3 просмотра · 7 ч назад
Brute to Best: every LeetCode problem, from the naive solution to the optimal one.
In this video:
The problem: each employee has a sorted list of working intervals. Return the finite time ranges when every employee is free.
Brute force: mark every time unit across all the schedules, which depends on the time range instead of the number of intervals.
The key insight: free time for everyone is just the gaps between the merged busy intervals.
Put all the intervals into one list, sort it by start, and merge as you go. Every gap between the merged end and the next start is free time.
Another option is a min-heap with one pointer per employee, which takes O(N log K).
Dry run: for the schedules 1–2 and 5–6, then 1–3, then 4–10, the only common free time is 3–4.
Complexity: O(N log N) time and O(N) space.
Problem: https://leetcode.com/problems/employe...
Related: Merge Intervals (56), Meeting Rooms II (253), Interval List Intersections (986)
Full Brute to Best playlist on the channel.
Subscribe for a new LeetCode problem, solved from brute force to the best solution, every day.
Hashtags
#leetcode #leetcode759 #employeefreetime #intervals #mergeintervals #heap #sorting #hard #coding #codinginterview #dsa #python #leetcodepremium #airbnb #brutetobest