[AlgoExpert] Laptop Rentals

Laptop Rentals

  • Time : O(nlogn)
  • Space : O(n)
1
2
3
4
5
6
7
8
9
10
11
12
int laptopRentals(vector<vector<int>> T) {
sort(begin(T), end(T));
int res = 0;
priority_queue<int, vector<int>, greater<int>> pq;
for(auto t : T) {
res = max(res, (int)pq.size());
int s = t[0], e = t[1];
while(!pq.empty() and pq.top() <= s) pq.pop();
pq.push(e);
}
return max(res, (int)pq.size());
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/05/10/PS/AlgoExpert/laptop-rentals/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.