There is a hypothetical web server which supports only one very simple API - count of requests received in the last hour, minute and second. This server is very popular in t
Following code is in JS. It will return you the count in O(1). I wrote this program for an interview where time was pre defined to be 5 minutes. But you can modify this code for seconds, minutes, and so on. Let me know how it goes.
In clean_hits method remove each entry (outside our time range) from the object that we created and subtract that count from totalCount before you delete the entry
this.hitStore = { "totalCount" : 0};