[InterviewBit] Meeting rooms

Meeting rooms

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Solution::solve(vector<vector<int> > &A) {
sort(begin(A), end(A));
priority_queue<int, vector<int>, greater<int>> q;
int l = 0, r = 0, n = A.size(), res = 0;
while(r < n) {
int s = A[l][0], e = A[r][0];
while(q.size() and q.top() <= s) q.pop();
while(r < n and A[r][0] == s) q.push(A[r++][1]);
res = max(res, (int)q.size());
l = r;
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/10/26/PS/interviewbit/meeting-rooms/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.