Skip to main content
Back to problems
Leetcode
Easy
Arrays
Simulation
Queues
Minimum Number of Chairs in a Waiting Room

Track arriving and leaving people to determine the maximum number of chairs needed at any moment.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Minimum Number of Chairs in a Waiting Room

You are given a string representing a sequence of events in a waiting room. Each character describes what happens at one step:

  • E means one person enters the room.
  • L means one person leaves the room.

A chair is needed for each person currently inside the room. Your task is to determine the minimum number of chairs that must be available so that everyone who is in the room at the same time has a chair.

In other words, compute the maximum number of people present in the room at any point while processing the events from left to right.

Notes

  • Assume the room starts empty.
  • The sequence is valid, so the number of people leaving never exceeds the number currently inside.
  • You only need to return the minimum chairs required, not the timeline.

Input Format

  • A single string events consisting only of the characters E and L.

Each character represents one event in order from left to right.

Output Format

  • Return a single integer: the minimum number of chairs required in the waiting room.

Constraints

  • 1events1051 \le |events| \le 10^5
  • events[i] is either E or L
  • The event sequence is valid
Examples
Sample cases returned by the problem API.

Example 1

Input

events = "EELLE"

Output

2

Explanation

The occupancy changes as 0 → 1 → 2 → 1 → 0 → 1, so the maximum number of people present at once is 2. That means 2 chairs are enough.

Example 2

Input

events = "ELELEL"

Output

1

Explanation

The room never has more than one person at a time, so only 1 chair is needed.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.