Session count by user
Your task
An access log records one line per API call as "<user> <ts>", where ts is integer Unix seconds, and the file is already in non-decreasing timestamp order. Analytics defines a session per user: a call starts a new session if it is the user's first call, or if more than gap seconds passed since that user's previous call (a difference of exactly gap continues the same session). Return a dictionary mapping each user to their number of sessions.
Examples
session_counts(lines: list[str], gap: int) -> dict[str,int]Example 1
Input
session_counts(["alice 100", "bob 130", "alice 160", "alice 400"], 120)Output
{"alice": 2, "bob": 1}