Sessionise the clickstream
A product-analytics team in Sao Paulo receives raw website events as HH:MM:SS user page (one day only). The events are not sorted. They want to know how users really behave in sessions.
For each user, sort that user's events by time. A new session starts at the user's first event, and also whenever the gap between two consecutive events (in time order) is strictly greater than G minutes. The duration of a session is its last event time minus its first event time, in seconds (a session with a single event lasts 0 seconds). Events with exactly the same second belong to the same session.
Task: line 1 is G, line 2 is N, then N event lines. For each user in alphabetical order (case-sensitive) print user sessions=S total=T longest=L pages=P, where S is the number of sessions, T the sum of all session durations, L the longest session duration and P the number of distinct pages the user visited overall.
Sample tests
Input
30 9 10:00:00 maria /home 10:10:00 maria /shop 09:00:00 maria /home 10:41:00 maria /cart 10:00:30 joao /home 10:20:30 joao /home 11:00:00 joao /faq 10:50:30 joao /faq 10:20:29 ana /x
Expected output
ana sessions=1 total=0 longest=0 pages=1 joao sessions=1 total=3570 longest=3570 pages=2 maria sessions=3 total=600 longest=600 pages=3
Input
5 3 12:00:00 u /a 12:05:00 u /a 12:10:01 u /b
Expected output
u sessions=2 total=300 longest=300 pages=2
Your answer is also checked against 3 hidden tests.
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
