Back to problems

Aggregate user logs into 30-minute sessions

Algorithm · Robinhood · Medium

Given a CSV-formatted string containing user activity records with fields user_id, log_datetime, and topic, process each user's activity into sessions. Each row represents one event. For every user_id, sort that user's rows by log_datetime ascending and split the sorted sequence into sessions. A session starts at the user's earliest event. For each following event, if the gap from the immediately preceding event is at most 30 minutes, it belongs to the current session. If…

Checking your access…