Uber | Onsite | metric collector
Anonymous User
1212

Design a metric collector, which has procide two function:
add(string metricName) -> add 1 to the metric
getMetricCount(string metricName) -> get the count of the metric within 100s

e.g.
Time
1 add(Test)
99 add(Test)
100 getMetricCount(Test) = 2
101 getMetricCount(Test) = 1

My solution:
unordered_map<string, deque<clock_t>> metrics, which store the timestamp of a log
when call getMetricCount, remove the logs that expires, then count the length in deque.

I think my solution isn't effecient, because it takes linear time when call getMetricCount, but I don't have other idea.

Comments (1)