2402. Meeting Rooms III Hard
1/**
2 * [2402] Meeting Rooms III
3 *
4 * You are given an integer n. There are n rooms numbered from 0 to n - 1.
5 * You are given a 2D integer array meetings where meetings[i] = [starti, endi] means that a meeting will be held during the half-closed time interval [starti, endi). All the values of starti are unique.
6 * Meetings are allocated to rooms in the following manner:
7 * <ol>
8 * Each meeting will take place in the unused room with the lowest number.
9 * If there are no available rooms, the meeting will be delayed until a room becomes free. The delayed meeting should have the same duration as the original meeting.
10 * When a room becomes unused, meetings that have an earlier original start time should be given the room.
11 * </ol>
12 * Return the number of the room that held the most meetings. If there are multiple rooms, return the room with the lowest number.
13 * A half-closed interval [a, b) is the interval between a and b including a and not including b.
14 *
15 * Example 1:
16 *
17 * Input: n = 2, meetings = [[0,10],[1,5],[2,7],[3,4]]
18 * Output: 0
19 * Explanation:
20 * - At time 0, both rooms are not being used. The first meeting starts in room 0.
21 * - At time 1, only room 1 is not being used. The second meeting starts in room 1.
22 * - At time 2, both rooms are being used. The third meeting is delayed.
23 * - At time 3, both rooms are being used. The fourth meeting is delayed.
24 * - At time 5, the meeting in room 1 finishes. The third meeting starts in room 1 for the time period [5,10).
25 * - At time 10, the meetings in both rooms finish. The fourth meeting starts in room 0 for the time period [10,11).
26 * Both rooms 0 and 1 held 2 meetings, so we return 0.
27 *
28 * Example 2:
29 *
30 * Input: n = 3, meetings = [[1,20],[2,10],[3,5],[4,9],[6,8]]
31 * Output: 1
32 * Explanation:
33 * - At time 1, all three rooms are not being used. The first meeting starts in room 0.
34 * - At time 2, rooms 1 and 2 are not being used. The second meeting starts in room 1.
35 * - At time 3, only room 2 is not being used. The third meeting starts in room 2.
36 * - At time 4, all three rooms are being used. The fourth meeting is delayed.
37 * - At time 5, the meeting in room 2 finishes. The fourth meeting starts in room 2 for the time period [5,10).
38 * - At time 6, all three rooms are being used. The fifth meeting is delayed.
39 * - At time 10, the meetings in rooms 1 and 2 finish. The fifth meeting starts in room 1 for the time period [10,12).
40 * Room 0 held 1 meeting while rooms 1 and 2 each held 2 meetings, so we return 1.
41 *
42 *
43 * Constraints:
44 *
45 * 1 <= n <= 100
46 * 1 <= meetings.length <= 10^5
47 * meetings[i].length == 2
48 * 0 <= starti < endi <= 5 * 10^5
49 * All the values of starti are unique.
50 *
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/meeting-rooms-iii/
55// discuss: https://leetcode.com/problems/meeting-rooms-iii/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60 pub fn most_booked(n: i32, meetings: Vec<Vec<i32>>) -> i32 {
61 0
62 }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_2402() {
73 }
74}
75
Back
© 2025 bowen.ge All Rights Reserved.