#3168
Easy Algorithms Minimum number of chairs in a waiting room
String Simulation
79.2% acceptance
Feb 24, 2026
155
14
You are given a string s. Simulate events at each second i:
If s[i] == 'E', a person enters the waiting room and takes one of the chairs in it.
If s[i] == 'L', a person leaves the waiting room, freeing up a chair.
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.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn minimum_chairs(s: String) -> i32 {
let mut count = 0i32;
let mut max_count = 0i32;
for &b in s.as_bytes() {
if b == b'E' {
count += 1;
max_count = max_count.max(count);
} else {
count -= 1;
}
}
max_count
}
}