3168. Minimum Number of Chairs in a Waiting Room Easy
1/**
2 * [3168] Minimum Number of Chairs in a Waiting Room
3 *
4 * You are given a string s. Simulate events at each second i:
5 *
6 * If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it.
7 * If s[i] == 'L', a person leaves the waiting room, freeing up a chair.
8 *
9 * Return the minimum number of chairs needed so that a chair is available for every person who enters the waiting room given that it is initially empty.
10 *
11 * <strong class="example">Example 1:
12 * <div class="example-block">
13 * Input: <span class="example-io">s = "EEEEEEE"</span>
14 * Output: <span class="example-io">7</span>
15 * Explanation:
16 * After each second, a person enters the waiting room and no person leaves it. Therefore, a minimum of 7 chairs is needed.
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">s = "ELELEEL"</span>
21 * Output: <span class="example-io">2</span>
22 * Explanation:
23 * Let's consider that there are 2 chairs in the waiting room. The table below shows the state of the waiting room at each second.
24 * </div>
25 * <table>
26 * <tbody>
27 * <tr>
28 * <th>Second</th>
29 * <th>Event</th>
30 * <th>People in the Waiting Room</th>
31 * <th>Available Chairs</th>
32 * </tr>
33 * <tr>
34 * <td>0</td>
35 * <td>Enter</td>
36 * <td>1</td>
37 * <td>1</td>
38 * </tr>
39 * <tr>
40 * <td>1</td>
41 * <td>Leave</td>
42 * <td>0</td>
43 * <td>2</td>
44 * </tr>
45 * <tr>
46 * <td>2</td>
47 * <td>Enter</td>
48 * <td>1</td>
49 * <td>1</td>
50 * </tr>
51 * <tr>
52 * <td>3</td>
53 * <td>Leave</td>
54 * <td>0</td>
55 * <td>2</td>
56 * </tr>
57 * <tr>
58 * <td>4</td>
59 * <td>Enter</td>
60 * <td>1</td>
61 * <td>1</td>
62 * </tr>
63 * <tr>
64 * <td>5</td>
65 * <td>Enter</td>
66 * <td>2</td>
67 * <td>0</td>
68 * </tr>
69 * <tr>
70 * <td>6</td>
71 * <td>Leave</td>
72 * <td>1</td>
73 * <td>1</td>
74 * </tr>
75 * </tbody>
76 * </table>
77 * <strong class="example">Example 3:
78 * <div class="example-block">
79 * Input: <span class="example-io">s = "ELEELEELLL"</span>
80 * Output: <span class="example-io">3</span>
81 * Explanation:
82 * Let's consider that there are 3 chairs in the waiting room. The table below shows the state of the waiting room at each second.
83 * </div>
84 * <table>
85 * <tbody>
86 * <tr>
87 * <th>Second</th>
88 * <th>Event</th>
89 * <th>People in the Waiting Room</th>
90 * <th>Available Chairs</th>
91 * </tr>
92 * <tr>
93 * <td>0</td>
94 * <td>Enter</td>
95 * <td>1</td>
96 * <td>2</td>
97 * </tr>
98 * <tr>
99 * <td>1</td>
100 * <td>Leave</td>
101 * <td>0</td>
102 * <td>3</td>
103 * </tr>
104 * <tr>
105 * <td>2</td>
106 * <td>Enter</td>
107 * <td>1</td>
108 * <td>2</td>
109 * </tr>
110 * <tr>
111 * <td>3</td>
112 * <td>Enter</td>
113 * <td>2</td>
114 * <td>1</td>
115 * </tr>
116 * <tr>
117 * <td>4</td>
118 * <td>Leave</td>
119 * <td>1</td>
120 * <td>2</td>
121 * </tr>
122 * <tr>
123 * <td>5</td>
124 * <td>Enter</td>
125 * <td>2</td>
126 * <td>1</td>
127 * </tr>
128 * <tr>
129 * <td>6</td>
130 * <td>Enter</td>
131 * <td>3</td>
132 * <td>0</td>
133 * </tr>
134 * <tr>
135 * <td>7</td>
136 * <td>Leave</td>
137 * <td>2</td>
138 * <td>1</td>
139 * </tr>
140 * <tr>
141 * <td>8</td>
142 * <td>Leave</td>
143 * <td>1</td>
144 * <td>2</td>
145 * </tr>
146 * <tr>
147 * <td>9</td>
148 * <td>Leave</td>
149 * <td>0</td>
150 * <td>3</td>
151 * </tr>
152 * </tbody>
153 * </table>
154 *
155 * Constraints:
156 *
157 * 1 <= s.length <= 50
158 * s consists only of the letters 'E' and 'L'.
159 * s represents a valid sequence of entries and exits.
160 *
161 */
162pub struct Solution {}
163
164// problem: https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room/
165// discuss: https://leetcode.com/problems/minimum-number-of-chairs-in-a-waiting-room/discuss/?currentPage=1&orderBy=most_votes&query=
166
167// submission codes start here
168
169impl Solution {
170 pub fn minimum_chairs(s: String) -> i32 {
171 0
172 }
173}
174
175// submission codes end
176
177#[cfg(test)]
178mod tests {
179 use super::*;
180
181 #[test]
182 fn test_3168() {
183 }
184}
185
Back
© 2025 bowen.ge All Rights Reserved.