Accounts Streaming From Two Devices at Once
Problem
A `stream_session` DataFrame logs viewing sessions. Each row has `profile_id`, `device_id`, `started_at` and `ended_at` (datetime strings). Each row is one session: a profile streamed from a device between `started_at` and `ended_at`.
A profile is flagged for sharing when it had **two sessions on different devices that overlapped in time** (one session started while another, on a different device, was still running). Return the distinct `profile_id` of every such profile.
Input data
Example rows — the live problem includes the full dataset.
| profile_id | device_id | started_at | ended_at |
|---|---|---|---|
| 1 | 100 | 2026-01-01 10:00:00 | 2026-01-01 11:00:00 |
| 1 | 200 | 2026-01-01 10:30:00 | 2026-01-01 12:00:00 |
| 2 | 300 | 2026-01-01 08:00:00 | 2026-01-01 09:00:00 |
| 2 | 400 | 2026-01-01 09:30:00 | 2026-01-01 10:00:00 |
Expected output
Your answer should return 1 row with the columns profile_id.
Starter code (Pandas (Python))
import pandas as pd
def overlapping_streams(stream_session: pd.DataFrame) -> pd.DataFrame:
# Your code here
return stream_sessionSolve 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