AnalystPath

Count Overlapping Room Bookings

PandasMediumMid level~10 min

Problem

An office tracks meeting-room reservations in a DataFrame `room_bookings` loaded from `room_bookings.csv`. Each row has a `room_id`, a `starts_at` time, and an `ends_at` time (strings like '09:00:00').

Two bookings for the same room overlap when one booking starts strictly before another booking, while the earlier one has not yet ended by the time the later one starts — i.e. for the same `room_id`, a pair (A, B) overlaps when `starts_at_a < starts_at_b` and `ends_at_a > starts_at_b`. Bookings that merely touch at an endpoint do not overlap.

For each room, count how many such overlapping pairs exist. Return a DataFrame with columns `room_id` and `overlap_count`, including only rooms that have at least one overlapping pair, ordered by `room_id`.

Input data

Example rows — the live problem includes the full dataset.

room_bookings
room_idstarts_atends_at
109:00:0010:30:00
110:00:0011:00:00
111:30:0012:00:00
213:00:0014:00:00
215:00:0016:00:00

Expected output

Your answer should return 2 rows with the columns room_id, overlap_count.

Starter code (Pandas (Python))

import pandas as pd

def overlap_pairs(room_bookings) -> pd.DataFrame:
    # Your code here
    return room_bookings

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions