Hotel Room Booking Problem

You are managing a hotel with 10 floors numbered from 0 to 9. Each floor contains 26 rooms labeled from A to Z. You will receive a sequence of strings representing room bookings where ‘+’ indicates a room is booked and ‘-’ indicates it is freed. Determine which room is booked the most times.

Input:

The first line contains an integer 'T' indicating the number of test cases.
For each test case, the first line contains an integer 'n', the number of booking or freeing operations.
The second line contains 'n' strings, each representing a room operation.

Output:

For each test case, output a string representing the room booked the most times. Print the results on separate lines for multiple test cases.

Example:

Input:
n = 6
Arr[] = {"+1A", "+3E", "-1A", "+4F", "+1A", "-3E"}
Output:
1A
Explanation:

In this example, room “1A” is booked 2 times, which is the highest. Therefore, the output is “1A”.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 104

Note: Assume the sequence of bookings and freings is always valid, meaning every freed room was previously booked. In case of a tie, return the lexicographically smaller room.

Be the first one to answer
Add answer anonymously...
Google Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter