Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- We are given a list schedule of employees, which represents the working time for each employee.
- Each employee has a list of non-overlapping Intervals, and these intervals are in sorted order.
- Return the list of finite intervals representing common, positive-length free time for all employees, also in sorted order.
- """
- # Definition for an Interval.
- # class Interval:
- # def __init__(self, start: int = None, end: int = None):
- # self.start = start
- # self.end = end
- class Solution:
- def employeeFreeTime(self, schedule: '[[Interval]]') -> '[Interval]':
- # Flattening the schedule
- intervals = [interval for employee in schedule for interval in employee]
- # Sorting by start of each Interval
- intervals.sort(key=lambda x: x.start)
- res, end = [], intervals[0].end
- # Checking for free time between intervals
- for i in intervals[1:]:
- if end < i.start:
- res.append(Interval(end, i.start))
- end = max(end, i.end)
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement