A product analytics pipeline receives a raw clickstream and must group each user's events into sessions. A session ends when a user is inactive for 30 minutes or more; the next event starts a new session.
The feed arrives unsorted, and a retry can deliver the same event_id twice.
events — a list of dicts:
| column | type | notes |
|---|---|---|
event_id | int | unique per event; duplicates may arrive |
user_id | str | |
ts | str | YYYY-MM-DD HH:MM:SS, arrives unsorted |
One row per session, as a list of dicts with keys in this order:
user_id, session_index, started_at, ended_at, event_count
session_index starts at 1 per user, ordered by time.
event_id before sessionizing; a duplicate must not inflate event_count.user_id, then session_index.events| ts | user_id | event_id |
|---|---|---|
| 2026-03-01 09:00:00 | u1 | 1 |
| 2026-03-01 09:20:00 | u1 | 2 |
| 2026-03-01 10:05:00 | u1 | 3 |
| user_id | session_index | started_at | ended_at | event_count |
|---|---|---|---|---|
| u1 | 1 | 2026-03-01 09:00:00 | 2026-03-01 09:20:00 | 2 |
| u1 | 2 | 2026-03-01 10:05:00 | 2026-03-01 10:05:00 | 1 |
events| ts | user_id | event_id |
|---|---|---|
| 2026-03-01 11:00:00 | u2 | 5 |
| 2026-03-01 09:10:00 | u1 | 1 |
| 2026-03-01 11:15:00 | u2 | 6 |
| 2026-03-01 09:00:00 | u1 | 2 |
| user_id | session_index | started_at | ended_at | event_count |
|---|---|---|---|---|
| u1 | 1 | 2026-03-01 09:00:00 | 2026-03-01 09:10:00 | 2 |
| u2 | 1 | 2026-03-01 11:00:00 | 2026-03-01 11:15:00 | 2 |
Community-reported interview topic. Not an official company question and no affiliation is implied.
Run against the public tests, or submit to score against all of them.