Sessionize clickstream
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) → dictExamples
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.
0:00 of about 35 min
solution.py
InputExpectedGot
[[["u1",0],["u1",30],["u1",200]],60]{"u1":2}not run yetsample