Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Minimum Number of Chairs in a Waiting Room

XPChallenge Points: 10
levelLevel: Easy

You’re given a string s where each character represents a per-second event:

  • 'E': one person enters and takes a chair,

  • 'L': one person leaves, freeing a chair.

Starting from an empty room, return the minimum number of chairs required so that every entrant always finds a chair.
This equals the maximum number of people simultaneously inside at any time.

Example 1:

Input: s = "EEEEEEE"

Output: 7

Explanation:

Every second someone enters; peak occupancy = 7 → chairs = 7.

Example 2:

Input: s = "ELELEEL"

Output: 2

Explanation:

0: E → inside 1 (peak 1) 1: L → inside 0 2: E → inside 1 3: L → inside 0 4: E → inside 1 5: E → inside 2 (peak 2) 6: L → inside 1 Peak = 2 → chairs = 2.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result