2dbi

K hotel bookings

viaLeetCode

Problem Given hotel booking requests as intervals [checkIn, checkOut) and K available rooms, determine whether all bookings can be honored (or: process bookings, accepting only those that fit) — the meeting-rooms-with-K-rooms problem in hotel clothing.

Input / Output

  • Input: intervals, int K.
  • Output: feasibility boolean (or max simultaneous rooms needed / accepted bookings per variant).

Constraints

  • Up to 10^5 bookings; O(n log n) expected. Checkout day is typically non-conflicting (half-open intervals) — clarify.

Example

  • Bookings [1,5), [2,6), [5,8) with K = 2 → feasible (max overlap 2: the [5,8) guest takes the room freed at 5).

Expected approach

  • Peak-overlap check: sort starts and ends separately, two-pointer sweep (+1 arrival, −1 departure with ends-first tie-break for half-open), track running occupancy; feasible iff peak <= K. Equivalent: min-heap of checkout times, size = rooms in use. Difference-array/BIT if dates are bounded integers. For the online/accept-reject variant, the heap formulation adapts naturally. Same skeleton as Minimum Train Platforms / Meeting Rooms II — recognizing that is the point.
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account