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.
The gap between 09:20 and 10:05 is 45 minutes, so:
event_id before sessionizing; a duplicate must not inflate event_count.user_id, then session_index.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.