Google: RateLimit

来源:互联网 发布:单片机蜂鸣器实验报告 编辑:程序博客网 时间:2024/05/29 23:45

转自: http://www.careercup.com/question?id=5147519440912384


This is two questions I got from a google interview. Not very sure how to solve it. Any comments would be appreciated. 

1. 
interface RateLimit { 
/** Sets the rate, from 1 to 1000000 queries per second */ 
void setQPS(int qps); 

/** accept or reject a request, called when request is received */ 
boolean allowThisRequest(); 


brief example: 
server instantiates your object, calls setQPS(1) 
at at time t, user1 makes a request, allowThisRequest() returns true 
at time t+0.01 sec, user2 makes a request, allowThisRequest() returns false 
at at time t+1, user4 makes a request, allowThisRequest() returns true 
at time t+5 sec, user3 makes a request, allowThisRequest() returns true


0 0
原创粉丝点击