AnalystPath

Accounts Streaming From Two Devices at Once

PandasMediumMid level~10 min

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.

stream_session
profile_iddevice_idstarted_atended_at
11002026-01-01 10:00:002026-01-01 11:00:00
12002026-01-01 10:30:002026-01-01 12:00:00
23002026-01-01 08:00:002026-01-01 09:00:00
24002026-01-01 09:30:002026-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_session

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