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
Why not just use a circular array? We have 3600 elements in that array.
index = 0;
Array[index % 3600] = count_in_one_second.
++index;
if you want last second, return the last element of this array. if you want last minute, return the sum of last 60 elements. if you want last hour, return the sum of the whole array (3600 elements).
Isn't his a simple and effective solution?
Thanks
Deryk