This Problem is not on leetcode it is already asked in google.
Description:
you have a list intervals of current meetings, and some meeting rooms with start and end timestamp.When a stream of new meeting ask coming in, check if it can be scheduled.A meeting room can only hold one meeting at a time. Each inquiry is independent.
Example 1:
Input:
Intervals:[[1,2],[4,5],[8,10]], rooms = 1, ask: [[2,3],[3,4]]
Output: [true,true]
Explanation:
For the ask of [2,3], we can arrange a meeting room room0.
The following is the meeting list of room0:
[[1,2], [2,3], [4,5], [8,10]]
For the ask of [3,4], we can arrange a meeting room room0.
The following is the meeting list of room0:
[[1,2], [3,4], [4,5], [8,10]]
Example 2:
Input:
[[1,2],[4,5],[8,10]]
1
[[4,5],[5,6]]
Output:
[false,true]
I am not able to pass all the test case Please help ! moreover it does not seems to be a optimized solution
class Solution {
public:
vector<bool> meetingRoomIII(vector<vector<int>> &intervals, int rooms, vector<vector<int>> &ask) {
int d[500000]={};
sort(ask.begin(),ask.end());
for(auto interval : intervals){
for(int i=interval[0];i<interval[1];i++){
d[i]++;
}
}
cout<<endl;
vector<bool>ans;
for(auto a : ask){
bool found=false;
for(int i=a[0];i<a[1];i++){
d[i]++;
if(d[i]>rooms && !found){
ans.push_back(false);
found=true;
}
}
if(found)for(int i=a[0];i<a[1];i++)d[i]--;
if(!found)ans.push_back(true);
}
return ans;
}
};