This question was asked by Riot Games.
Design and implement a HitCounter
class that keeps track of requests (or hits). It should support the following operations:
record(timestamp)
: records a hit that happened attimestamp
total()
: returns the total number of hits recordedrange(lower, upper)
: returns the number of hits that occurred between timestampslower
andupper
(inclusive)
Follow-up: What if our system has limited memory?