Peak Requests and Concurrent Users from Logs

Problem A web server writes one log file per day. Each line records either a request with its timestamp, or a session event (login or logout) with a user id and timestamp. Compute two peak statistics: the maximum number of requests in any one-second window, and the maximum number of users logged in simultaneously at any instant.

Input / Output

  • Input: a list of log entries, each either REQUEST <timestamp> or LOGIN|LOGOUT <user_id> <timestamp>.
  • Output: two integers — peak requests per second, and peak concurrent users.

Constraints

  • The log may hold millions of lines for a single day; an O(n^2) pairwise scan is too slow.
  • Timestamps have at least one-second resolution and are not guaranteed sorted.
  • Memory should stay proportional to the number of entries.
  • Every login has a matching logout (or an implicit logout at end of day).

Example

  • Requests at 12:00:00.1, .7, .9, and 12:00:01.2 → peak requests/sec = 3 (bucket 12:00:00–12:00:01).
  • Sessions: A 10:00–10:30, B 10:15–10:45, C 10:40–11:00 → peak concurrent = 2 (C starts before B ends).
asked …
LeaderboardSalaryAccount
Peak Requests and Concurrent Users from Logs · 2dbi