Find the days with maximum hotel occupancy from a month of bookings

Quick Overview

Given hotel bookings as check-in and check-out days within one month, return every day that has the highest number of guests present, in ascending order. It tests counting overlaps of half-open intervals, off-by-one handling on the check-out day, and returning all tied days.

Find the days with maximum hotel occupancy from a month of bookings

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given a list of `bookings` for a hotel in a single month, find the day or days with the maximum number of simultaneous guests. Each booking is a pair `[check_in, check_out]`, where `check_in` is the day the guest arrives and `check_out` is the day the guest departs. A guest occupies the hotel from day `check_in` to day `check_out - 1` inclusive. In other words, the guest is present on the check-in day but not on the check-out day. Return a list of all days that have the maximum occupancy, sorted in ascending order. ### Function Signature ```python def max_occupancy_days(bookings: list[list[int]]) -> list[int]: ``` ### Rules - Each booking is one guest. - A booking `[check_in, check_out]` counts on days `check_in` through `check_out - 1`. It does not count on `check_out`. - Days run from 1 to 31. Return every day whose occupancy equals the maximum, in ascending order. ### Constraints - `1 <= len(bookings) <= 10^4` - `1 <= check_in < check_out <= 31` - All days fall within the same month (days 1 to 31). ### Examples ```text Input: bookings = [[1, 4], [2, 6], [3, 5], [5, 8]] Output: [3] ``` The guest counts for days 1 to 8 are 1, 2, 3, 2, 2, 1, 1, 0. Day 3 is the only day when the first three guests are all present. ```text Input: bookings = [[1, 3], [2, 4], [3, 5], [4, 6]] Output: [2, 3, 4] ``` The counts for days 1 to 5 are 1, 2, 2, 2, 1. On day 3 the first guest has already checked out, so only the second and third guests are present. ```text Input: bookings = [[1, 2], [2, 3]] Output: [1, 2] ``` The first guest leaves on day 2, the same day the second guest arrives, so each of days 1 and 2 has exactly one guest.

Overview: Given hotel bookings as check-in and check-out days within one month, return every day that has the highest number of guests present, in ascending order. It tests counting overlaps of half-open intervals, off-by-one handling on the check-out day, and returning all tied days.

General logo
General
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given a list of bookings for a hotel in a single month, find the day or days with the maximum number of simultaneous guests.

Each booking is a pair [check_in, check_out], where check_in is the day the guest arrives and check_out is the day the guest departs. A guest occupies the hotel from day check_in to day check_out - 1 inclusive. In other words, the guest is present on the check-in day but not on the check-out day.

Return a list of all days that have the maximum occupancy, sorted in ascending order.

Function Signature

def max_occupancy_days(bookings: list[list[int]]) -> list[int]:

Rules

  • Each booking is one guest.
  • A booking [check_in, check_out] counts on days check_in through check_out - 1 . It does not count on check_out .
  • Days run from 1 to 31. Return every day whose occupancy equals the maximum, in ascending order.

Constraints

  • 1 <= len(bookings) <= 10^4
  • 1 <= check_in < check_out <= 31
  • All days fall within the same month (days 1 to 31).

Examples

Input: bookings = [[1, 4], [2, 6], [3, 5], [5, 8]]
Output: [3]

The guest counts for days 1 to 8 are 1, 2, 3, 2, 2, 1, 1, 0. Day 3 is the only day when the first three guests are all present.

Input: bookings = [[1, 3], [2, 4], [3, 5], [4, 6]]
Output: [2, 3, 4]

The counts for days 1 to 5 are 1, 2, 2, 2, 1. On day 3 the first guest has already checked out, so only the second and third guests are present.

Input: bookings = [[1, 2], [2, 3]]
Output: [1, 2]

The first guest leaves on day 2, the same day the second guest arrives, so each of days 1 and 2 has exactly one guest.