File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ fun mostBooked (n : Int , meetings : Array <IntArray >): Int {
3
+ meetings.sortBy { it[0 ] }
4
+
5
+ val available = PriorityQueue <Int > ().apply {
6
+ for (i in 0 until n)
7
+ add(i)
8
+ }
9
+
10
+ val used = PriorityQueue <Pair <Int , Int >> { a, b ->
11
+ if (a.first == b.first) a.second - b.second
12
+ else a.first - b.first
13
+ }
14
+
15
+ val count = IntArray (n)
16
+
17
+ for (meet in meetings) {
18
+ var (start, end) = meet
19
+ while (used.isNotEmpty() && start >= used.peek().first) {
20
+ val (_, room) = used.poll()
21
+ available.add(room)
22
+ }
23
+
24
+ if (available.isEmpty()) {
25
+ val (endTime, room) = used.poll()
26
+ end = endTime + (end - start)
27
+ available.add(room)
28
+ }
29
+
30
+ val room = available.poll()
31
+ used.add(end to room)
32
+ count[room]++
33
+ }
34
+
35
+ return count.indexOfFirst({ it == (count.max() ? : 0 ) })
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments