Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT: I assumed this question wasn't about getting a real-time answer for the question "how many users are active <em>now</em>", but rather getting historical values - how many users were active at 3:25PM. I'm keeping the old solution below the new one:</p> <p>So, you want to know how many users are active now, Keep a queue per game. Whenever you see a new log entry, find out which game it belongs to, and add it to the game's queue. After each addition clean up old entries at the beginning of the queue (all entries older than 1 minute at the time of the clean-up).</p> <p>When asked for the number of active users in a game, do the same clean-up on the game's queue, and return the queue's depth.</p> <p>Keep a hash mapping the games to the queues, and you got an O(N) operation with N being the number of lines in the log - each line is processed at most twice - once for adding it, once for removing it. You also do an additional comparison per addition and look-up (when deciding a queue entry is <em>not</em> old enough), but that's constant time times N. So O(N) in all.</p> <p>Previous answer to that other question: Seeing there aren't all that many minutes (1440 a day), I would create a vector for each game, with a slot for each minute.</p> <p>Go over the log file, for each line get the time, round it up to the closest minute and add 1 to the appropriate slot in the array. Once you're done, you'll know exactly how many active users were for each game at every minute.</p> <p>Complexity - O(N), with N being the number of lines in the log file.</p> <p>To support multiple games, just use a hash to map from the game's name to its vector.</p> <p>Now, this assumes you only check for active users at whole minute boundries (1:00:00, 1:01:00, etc...). This is probably what you're required to do anyway.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload