← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Different events stream into the system. Design a counter that supports recording events of various types and querying how many events of a given type occurred within an inclusive time range.
Implement the EventCounter class:
EventCounter() Initializes the counter.void receive(string eventType, int timestamp) Records that an event of eventType occurred at timestamp.int count(string eventType, int startTime, int endTime) Returns the number of events of eventType whose timestamp falls in [startTime, endTime] (both ends inclusive).
You may assume timestamps passed to receive are non-decreasing across calls.EventCounter ec = new EventCounter(); ec.receive("login", 1); ec.receive("login", 3); ec.receive("signup", 4); ec.receive("login", 7); ec.receive("login", 10); ec.count("login", 2, 8); // returns 2 (timestamps 3, 7) ec.count("login", 1, 10); // returns 4 (timestamps 1, 3, 7, 10) ec.count("signup", 1, 5); // returns 1 (timestamp 4) ec.count("signup", 5, 10); // returns 0 ec.count("logout", 1, 100); // returns 0 (event type never seen)