Hotel Rooms - Minimum Rooms Required - aloalgo

Hotel Rooms - Minimum Rooms Required

Medium

You are given an array interval objects. Each interval is represented as a pair of integers, [check_in_day, check_out_day].

Your task is to determine the minimum number of rooms required to fulfill all the booking requirements.

You may assume that:

  • For any given interval [start, end], start will always be strictly less than end.
  • A booking ending at a certain date does not conflict with another starting at the exact same date. For example, a booking from (8, 9) does not conflict with a meeting from (9, 10).

Return the minimum number of rooms as an integer.

Example 1

Input
[
  [1, 2],
  [3, 4]
]
Output
1
Explanation:

Booking [1,2] uses a room from day 1 to day 2.

Booking [3,4] uses the same room from day 3 to day 4. Since there is no overlap, only one room is required.

Example 2

Input
[
  [1, 3],
  [2, 4],
  [3, 5]
]
Output
3
Explanation:

On day 1, booking [1,3] is active (1 room).

On day 2, bookings [1,3] and [2,4] are active (2 rooms).

On day 3, bookings [1,3], [2,4], and [3,5] are all active at the start of the day before [1,3] checks out (3 rooms).

Thus, a maximum of 3 rooms are needed concurrently.

Example 3

Input
[
  [1, 10],
  [2, 3],
  [4, 5],
  [6, 7]
]
Output
2
Explanation:

The booking [1,10] requires one room for a long duration. The other bookings [2,3], [4,5], and [6,7] can use a second room sequentially as they do not overlap with each other, but they all overlap with [1,10]. Therefore, two rooms are required.

Loading...
Input
[
  [1, 2],
  [3, 4]
]
Output
1

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!