Most Booked Hotel Room
Learn this problemProblem statement
Given a hotel which has 10 floors [0-9] and each floor has 26 rooms [A-Z]. You are given a sequence of rooms, where + suggests room is booked, - room is freed. You have to find which room is booked maximum number of times.
You may assume that the list describes a correct sequence of bookings in chronological order; that is, only free rooms can be booked and only booked rooms can be freed. All rooms are initially free. Note that this does not mean that all rooms have to be free at the end. In case, 2 rooms have been booked the same number of times, return the lexicographically smaller room.
Function
mostBookedHotelRoom(A: String[]) → String
Complete the function mostBookedHotelRoom in the editor.
mostBookedHotelRoom has the following parameter:
String[] A: an array of strings representing the sequence of room bookings and releases
Returns
String: the room that is booked the maximum number of times
Examples
Example 1
A = ["+1A", "+3E", "-1A", "+4F", "+1A", "-3E"]return = "1A"1A has been booked 2 times, which is the maximum number of bookings for any room.Constraints
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026