Skip to content

Commit a190b0c

Browse files
committed
Meeting rooms
1 parent 18d3c1e commit a190b0c

7 files changed

Lines changed: 194 additions & 0 deletions

File tree

‎Third Interview/Microsoft/Algorithms/MeetingRooms/.idea/description.html‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Algorithms/MeetingRooms/.idea/misc.xml‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Algorithms/MeetingRooms/.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Algorithms/MeetingRooms/.idea/project-template.xml‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Third Interview/Microsoft/Algorithms/MeetingRooms/.idea/workspace.xml‎

Lines changed: 127 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
12+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.company;
2+
3+
import java.util.*;
4+
5+
// https://www.programcreek.com/2014/05/leetcode-meeting-rooms-ii-java/
6+
7+
public class Main {
8+
9+
private int meetingRooms(int[][] intervals){
10+
11+
Arrays.sort(intervals, Comparator.comparing((int[] intv) -> intv[0]));
12+
13+
PriorityQueue<Integer> heap = new PriorityQueue<>();
14+
15+
int count = 0;
16+
17+
for(int[] intv : intervals){
18+
if(heap.isEmpty()){
19+
count++;
20+
heap.offer(intv[1]);
21+
} else {
22+
if(intv[0] >= heap.peek())
23+
heap.poll();
24+
else
25+
count++;
26+
heap.offer(intv[1]);
27+
}
28+
}
29+
return count;
30+
}
31+
}

0 commit comments

Comments
 (0)