Count Overlapping Room Bookings
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_id | starts_at | ends_at |
|---|---|---|
| 1 | 09:00:00 | 10:30:00 |
| 1 | 10:00:00 | 11:00:00 |
| 1 | 11:30:00 | 12:00:00 |
| 2 | 13:00:00 | 14:00:00 |
| 2 | 15:00:00 | 16: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_bookingsSolve 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