algoadvance

Leetcode Question: 3168 ************************************************
3168. Minimum Number of Chairs in a Waiting Room
************************************************

You are given a string s. Simulate events at each second i:

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.

 

Example 1:

Input: s = "EEEEEEE"

Output: 7

Explanation:

After each second, a person enters the waiting room and no person leaves it. Therefore, a minimum of 7 chairs is needed.

Example 2:

Input: s = "ELELEEL"

Output: 2

Explanation:

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.

SecondEventPeople in the Waiting RoomAvailable Chairs
0Enter11
1Leave02
2Enter11
3Leave02
4Enter11
5Enter20
6Leave11

Example 3:

Input: s = "ELEELEELLL"

Output: 3

Explanation:

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.

SecondEventPeople in the Waiting RoomAvailable Chairs
0Enter12
1Leave03
2Enter12
3Enter21
4Leave12
5Enter21
6Enter30
7Leave21
8Leave12
9Leave03

 

Constraints:





Solutions: Python   Java  C++
Cut study time in HALF and DOMINATE your interview with AlgoAdvance AI