Sessionize clickstream

Write codeHard35 minDatabricks and Snowflake style

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) -> dict
Example 1
Inputcount_sessions([["u1", 0], ["u1", 30], ["u1", 200]], 60)
Output{"u1": 2}