-
Notifications
You must be signed in to change notification settings - Fork 0
/
minimumMeetingRooms.js
56 lines (51 loc) · 1.16 KB
/
minimumMeetingRooms.js
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
51
52
53
54
55
56
function minRooms(A) {
let startArr = A.map((row)=>{return row[0]}).sort((a,b)=>{return a-b});
let depArr = A.map((row)=>{return row[1]}).sort((a,b)=>{return a-b});
console.log(startArr);
console.log(depArr);
let roomsCount = 0, maxRoomsCount = 0, startIndex = 0, depIndex = 0;
while(startIndex < startArr.length && depIndex < depArr.length) {
console.log(startArr[startIndex]+"_"+depArr[depIndex])
if(startArr[startIndex] < depArr[depIndex]){
roomsCount++;
startIndex++;
} else {
roomsCount--;
depIndex++;
}
maxRoomsCount = Math.max(maxRoomsCount, roomsCount);
}
console.log(maxRoomsCount)
return maxRoomsCount;
}
let testCase = [
[
[0, 30],
[5, 10],
[15, 20]
],
[
[1, 18],
[18, 23],
[15, 29],
[4, 15],
[2, 11],
[5, 13]
],
[
[0, 14],
[6, 25],
[12, 19],
[13, 19],
[5, 9]
],
[
[7, 10],
[4, 19],
[19, 26],
[14, 16],
[13, 18],
[16, 21]
]
]
minRooms(testCase[3]);