EASY
3168. Minimum Number of Chairs in a Waiting Room
You are given a string s representing the sequence of arrivals and departures in a waiting room. Each character is either 'E' (enter) or 'L' (leave). Return the minimum number of chairs needed so that no one has to stand at any time.
Example
Input:
s = "ELEELEELLL"
2
Constraints
- 1 ≤ s.length ≤ 100
- s consists only of 'E' and 'L'.
Solution: Simulation
- Time Complexity: O(n), where n is the length of s.
- Space Complexity: O(1)
C++
class Solution {
public:
int minimumChairs(string s) {
int curr = 0, res = 0;
for (char c : s) {
if (c == 'E') curr++;
else curr--;
res = max(res, curr);
}
return res;
}
};