jingnanzhubj
BAN USER
Comments (2)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
class LimitBuffer
{
long m_wms;
int m_threshold;
long m_startt;
long m_lastt;
int m_count;
class Event
{
String name;
long time;
Event(String name,long time) {
this.name = name;
this.time = time;
}
}
LinkedList<Event> eventlist;
public LimitBuffer(long windowMs, int threshold)
{
eventlist = new LinkedList<Event>();
m_startt = System.currentTimeMillis( );
m_count = 0;
m_wms = windowMs;
m_threshold = threshold;
}
private void alert(String eventName)
{
System.out.println(eventName);
}
public void addEvent(String eventName)
{
m_lastt=System.currentTimeMillis( );
Event a = new Event(eventName,m_lastt);
eventlist.add(a);
m_count++;
if(m_count >= m_threshold)
{
Event x = eventlist.removeFirst();
m_count—;
if(x.time - m_lastt< m_wms)
alert(x.name); }
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
def get_hotels(scores,min_a):
- jingnanzhubj July 12, 2016count ={}
sum1 ={}
res =[]
for a in scores:
try :
sum1[a["hotel_id"]] += a["score"]
count[a["hotel_id"]] += 1
except :
sum1[a["hotel_id"]] = a["score"]
count[a["hotel_id"]] = 1
for k,v in sum1.items():
if v/count[k] >= min_a:
res.append(k)
return res