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.

AnswerBot
4mo

Given a sequence of room bookings and freeings, find the room that is booked the most times.

  • Create a hashmap to store the count of each room booking.

  • Iterate through the sequence of bookings and freein...read more

Help your peers!
Select
Add answer anonymously...

Google Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Majority Element - II Problem Statement Given an array/list ARR of integers with...read more
A Software Developer Intern was asked Q. Consecutive Elements Given an array arr of N non-negative integers, determine wh...read more
A Software Developer Intern was asked Q. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Majority Element - II Problem Statement Given an array/list ARR of integers with...read more
A Software Developer Intern was asked Q2. Consecutive Elements Given an array arr of N non-negative integers, determine wh...read more
A Software Developer Intern was asked Q3. Minimum Removals Problem Statement Given an integer array ARR of size N and an i...read more
Google Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits