Most Booked Room Log
EasyHash Map · Google
A hotel records every event in logs, in chronological order. Each entry is a string:
"+"followed by a room id means the room was booked (checked into), for example"+1A";"-"followed by a room id means the room was freed, for example"-1A".
A room id is one digit followed by one uppercase letter. The log is valid: a room is only freed while it is booked, and an occupied room is never booked again until it is freed.
Return the id of the room that was booked the most times (only + entries count). If several rooms tie, return the lexicographically smallest id.
Example 1
- Input:
- logs = ["+2C", "+7A", "-2C", "+2C", "-7A", "-2C", "+7A", "+3B"]
- Output:
- "2C"
- Explanation
- Room
2Cis booked twice and so is7A, while3Bis booked once. The tie between2Cand7Agoes to the lexicographically smaller id,"2C".
Example 2
- Input:
- logs = ["+4D", "-4D", "+4D", "-4D", "+1A"]
- Output:
- "4D"
- Explanation
4Dis booked twice (the-entries are check-outs and do not count), while1Ais booked once, so"4D"wins even though1Ais smaller.
Example 3
- Input:
- logs = ["+9Z"]
- Output:
- "9Z"
- Explanation
- Only one room is ever booked.
Constraints
1 <= logs.length <= 10^5- Every entry is
"+"or"-"followed by a digit0-9and a letterA-Z - At least one entry is a booking