Sessionize clickstream
Your task
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.
Examples
count_sessions(events: list[list], timeout: int) -> dictExample 1
Input
count_sessions([["u1", 0], ["u1", 30], ["u1", 200]], 60)Output
{"u1": 2}