spiralgo / algorithms

We voluntarily solve algorithm problems on this repo.
24 stars 7 forks source link

759. Employee Free Time #354

Closed ErdemT09 closed 3 years ago

ErdemT09 commented 3 years ago

Resolves: #91

Algorithm:

The point here is that any free time interval of the employees is equivalent to some time interval beginning at the end of one employee's time and ending at the other's start, where the start is later the end of the previous interval. We can then just iterate over the intervals sorted by their starting time, and add new free time intervals if the current start is later than the latest end time we have encountered. For recording the latest end time, we would simply need an integer. To iterate over the intervals in such a sorted manner, we can either directly sort it or use a priority queue.

One can also revisit #64 in order to perhaps get a view of this problem from another point.

altay9 commented 3 years ago

It is how we got the result: [[5,6],[7,9]]

IMG-1707