Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/594a448b199f453046b5f7a4ac9c0cf3 to your computer and use it in GitHub Desktop.
Save jianminchen/594a448b199f453046b5f7a4ac9c0cf3 to your computer and use it in GitHub Desktop.
Leetcode 253 meeting room II - line sweep algorithm
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...]
(si < ei), find the minimum number of conference rooms required.
For example,
Given [[0, 30],[5, 10],[15, 20]],
return 2.
// time -> counter
// time -> start -> +1 counter
// time -> finish -> - counter
0 -> 1
5 -> 1
10 -> -1
15 -> 1
20 -> -1
30 -> -1
time: O(N logN) - sorting takes O(nlgN)
space: O(N)
Sweep line approach
https://github.com/pllk/cphb/blob/master/book.pdf (p. 275)
| |
|------------
| ----------------
| ----------
| -----
|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment