Code Room
CodingHardcod-g685
Subject Data wranglingLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development, Technology

Question

Sessionize a clickstream. You are given events as [user_id, timestamp] (timestamps are integer seconds, NOT pre-sorted). Group each user's events into sessions: within a user, two consecutive events (after sorting by time) belong to the same session if the gap between them is at most `timeout` seconds; a larger gap starts a new session. Return a dict mapping each user_id to their number of sessions. A user with at least one event has at least one session.

Implement
count_sessions(events: list[list], timeout: int) → dict
Examples
in[[["u1",0],["u1",30],["u1",200]],60]out{"u1":2}
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.