-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeeting_Rooms_III.java
More file actions
50 lines (50 loc) · 1.46 KB
/
Meeting_Rooms_III.java
File metadata and controls
50 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.*;
import java.io.*;
import java.lang.*;
public class Meeting_Rooms_III {
class Solution {
public int mostBooked(int n, int[][] meetings) {
Arrays.sort(meetings , (a , b) -> a[0] - b[0]);
int[] roomcount = new int[n];
long[] endtime = new long[n];
for(int i = 0 ; i<meetings.length ; i++)
{
int st = meetings[i][0];
int ed = meetings[i][1];
boolean a = false;
int min_ind = -1;
long val = Long.MAX_VALUE;
for(int j = 0 ; j<n ; j++)
{
if(endtime[j]<val)
{
val = endtime[j];
min_ind = j;
}
if(endtime[j] <= st)
{
a = true;
roomcount[j]++;
endtime[j] = ed;
break;
}
}
if(!a)
{
roomcount[min_ind]++;
endtime[min_ind] += (ed-st);
}
}
int max = -1 , ind = -1;
for(int i = 0 ; i<n ; i++)
{
if(roomcount[i]>max)
{
max = roomcount[i];
ind = i;
}
}
return ind;
}
}
}