Peak Concurrency and Total Overlap of Maintenance Windows
Problem
An infrastructure team schedules maintenance windows in a DataFrame `maintenance_windows` loaded from `maintenance_windows.csv`. Each row has a `server_id`, an `opened_at` timestamp, and a `closed_at` timestamp (strings like '2024-06-01 01:00:00'). Windows on the same server can overlap in time.
For every server return two figures:
- `peak_concurrent_windows` — the maximum number of that server's windows that are simultaneously open at any instant.
- `total_overlap_minutes` — the sum, over every ordered pair of overlapping windows on that server, of the length in whole minutes the two windows share. A pair (A, B) overlaps when A opens before B (`opened_at_a < opened_at_b`) and A is still open when B opens (`closed_at_a > opened_at_b`); the shared length is MIN(closed_a, closed_b) minus MAX(opened_a, opened_b), truncated to whole minutes via Julian-day arithmetic (matching the SQL twin's `julianday(...)*1440` cast). A server with no overlapping pair reports 0.
Return one row per server with columns `server_id`, `peak_concurrent_windows`, `total_overlap_minutes`, ordered by `server_id`.
Input data
Example rows — the live problem includes the full dataset.
| server_id | opened_at | closed_at |
|---|---|---|
| 1 | 2024-06-01 01:00:00 | 2024-06-01 03:00:00 |
| 1 | 2024-06-01 02:00:00 | 2024-06-01 04:00:00 |
| 1 | 2024-06-01 02:30:00 | 2024-06-01 05:00:00 |
| 2 | 2024-06-01 08:00:00 | 2024-06-01 09:00:00 |
| 2 | 2024-06-01 10:00:00 | 2024-06-01 11:00:00 |
Expected output
Your answer should return 3 rows with the columns server_id, peak_concurrent_windows, total_overlap_minutes.
Starter code (Pandas (Python))
import pandas as pd
def server_overlap(maintenance_windows) -> pd.DataFrame:
# Your code here
return maintenance_windowsSolve 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