Ctrl K

How Many Parking Spots

Easy
A parking lot log is the string log, one character per event in time order: 'E' means a car drove in and took a spot, 'L' means a car drove out and freed one. The lot starts empty, and the log is consistent: only a car that is parked can leave. Return the smallest number of spots that guarantees every arriving car finds a free one.
Example 1
log="EELEL" → 2

After the second event two cars are inside, and there are never more at once.

Example 2
log="EEE" → 3

Three cars came in and none left.

Example 3
log="ELELEL" → 1

Cars come and go one at a time, so a single spot is enough.

Constraints
  • 1 ≤ len(log) ≤ 10⁵
  • log consists only of 'E' and 'L'
  • At no point have more cars left than entered
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyCounting Off by Threes and Fives EasyAdding Long Numbers in Strings EasyDrone Back on the Pad EasySame Text After Erasing Easy
loading Python…
Input
log="EELEL"
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.