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
My solution :
Maintain a hash of 3600 ,which contains a count,timestamp as fields.
For each request for:
Case(1) : if i/p timestamp==hash[idx].timestamp,hash[count]++;
Case(2) : if i/p timestamp>hash[idx].timestamp,then hash[idx].count=1 and hash[idx].timestamp=inputTimeStamp
Case(3): : if i/p timestamp
Now for any query for last second,minute,hour: Find idx as above, and as long as the timestamp matches with in given second/range/minute,keep on iterating back from from idx in circular manner.