[InterviewBit] Hotel Bookings Possible

Hotel Bookings Possible

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
11
12
13
bool Solution::hotel(vector<int> &arrive, vector<int> &depart, int K) {
priority_queue<int,vector<int>,greater<int>> q;
vector<pair<int,int>> A;
for(int i = 0; i < arrive.size(); i++) A.push_back({arrive[i], depart[i]});
sort(begin(A), end(A));
for(auto [a,d] : A) {
while(q.size() and q.top() < a) q.pop();
q.push(d);
if(q.size() > K) return false;
}
return true;
}

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