Round 1
Questions: Implement a Counter class that has the following methods:
put(number)
: put the number to the data structurecount(number)
: count the number of timesnumber
was put during the lastwindow=5 minutes
countAll()
: count the number of times any number was put during the lastwindow=5 minutes
.
Example:
At t = 10PM, put(2)
At t = 10:02PM, put(2)
At t = 10:03PM, put(3)
At t = 10:04PM, count(2)
should return 2
At t = 10:04PM, countAll()
should return 3
At t = 10:06PM, count(2)
should return 1 (the one that was put at 10:02PM)
At t = 10:06PM, countAll()
should return 2
Follow-up Questions:
- If you were to write unit tests, what would they be?
- If your code was to be in production, what issues may it cause?
Candidate's Approach
No approach provided.
Interviewer's Feedback
No feedback provided.