Given an array of meeting time intervals consisting of start and end times i.e [[0, 30],[5, 10],[15, 20]].

How to find the minimum number of conference rooms required without priority queue?

Output : 2

Given an array of meeting time intervals consisting of start and end times i.e [[0, 30],[5, 10],[15, 20]].

How to find the minimum number of conference rooms required without priority queue?

Output : 2

I have written a code based on your question.

**NEW EDIT: Re-written**

```
#include<bits/stdc++.h>
using namespace std;
int roomsneeded(vector< int > start, vector< int > over, int n)
{
sort(start.begin(), start.end());
sort(over.begin(), over.end());
int rooms_needed = 1, result = 1;
int i = 1, j = 0;
while (i < n && j < n)
{
if (start[i] < over[j])
{
rooms_needed++;
i++;
if (rooms_needed > result)
result = rooms_needed;
}
else
{
rooms_needed--;
j++;
}
}
return result;
}
int main()
{
vector< int > start,over;
int noofconf,starttime,endtime;
cin>>noofconf;
for(int i = 0 ; i < noofconf ; i++)
{
cin>>starttime>>endtime;
start.push_back(starttime);
over.push_back(endtime);
}
cout << roomsneeded(start, over, noofconf);
return 0;
}
```

Some help from :- http://www.geeksforgeeks.org/minimum-number-platforms-required-railwaybus-station/

I have tested a lot. Itâ€™s 100% true. (I thinkâ€¦)

test1 : http://ideone.com/hCoeC6

test2 : http://ideone.com/pM0iPu

Please let me know if itâ€™s failing on any test data.

1 Like

Your code may something wrongâ€¦because

Input :

3

1 3

2 4

3 5

Your code show output : 4

Corrected Output : 2

I have collected a code from internetâ€¦but could not understandâ€¦link : http://ideone.com/Dasz1D

It will be very helpful if u can simply implement that codeâ€¦

Please see the edited code.

I have tried in Js.Below is the script.

function result(){

var bigArray = [[0, 30],[5, 10],[15, 20]];

var conferenceRoom = 1; var index = 1;

for(i=0;i<bigArray.length-index;i++)

if(bigArray[i][0]<=bigArray[i+index][0] && bigArray[i][index]>=bigArray[i+index][0])

```
conferenceRoom++;
alert("Conference room needed : "+ conferenceRoom);
```

}

yeapâ€¦But How to solve this using greedy???