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.
Examples
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.
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.
Constraints
1 <= s.length <= 50
s consists only of the letters 'E' and 'L'.
s represents a valid sequence of entries and exits.
3168. Minimum Number of Chairs in a Waiting Room
Easy
10 Points
String
Simulation
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.
Examples
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.
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.
Constraints
1 <= s.length <= 50
s consists only of the letters 'E' and 'L'.
s represents a valid sequence of entries and exits.
Minimum Number of Chairs in a Waiting Room - Practice Coding | SlaveCode