🧭 Do not search for the first 15 minutes. When stuck: re-read the requirements → define I/O → choose the data structure → trace a small example by hand → write code.
Implement build_sessions(events, gap), which groups a user event log into sessions.
events = [("A", 1), ("A", 2), ("A", 10), ("A", 11), ("B", 3)]
Tuples of (user, timestamp). They are not guaranteed to be sorted — one user's
events may arrive interleaved and out of order.
gap (> gap). A gap of exactly gap stays in the same session.build_sessions(events, gap=5)
# {"A": [[1, 2], [10, 11]], "B": [[3]]}
Implement build_sessions(events, gap). gap is an integer of 0 or more.