Calculate Max Requests/Sec and Max Concurrent Users From a Log File
viaGlassdoor
Problem: Given a log file containing all requests received on a single day (with timestamps, and login/logout events), calculate (1) the maximum number of requests per second, and (2) the maximum number of concurrently active users.
Constraints: The log can be large; process it efficiently (sorting-based, not naive O(n^2) scanning).
Example: A log line might record a request timestamp, or a login/logout event with a user id and timestamp.
Approach:
- Max requests/sec: read all request timestamps, sort them, then group by 1-second buckets (e.g., 12:00:00-12:00:01) and take the maximum bucket size. This is O(n log n) for the sort plus O(n) for the grouping pass.
- Max concurrent users: treat each login as +1 and each logout as -1 on a running counter. Sort all login/logout events by timestamp, replay them in order incrementing/decrementing the counter, and track the running maximum — this is the classic "meeting rooms / max overlapping intervals" pattern.
asked …