t*8 发帖数: 14 | 1 收到的消息的结构如下
# Message examples:
#
# (business_name, ip, timestamp)
# (“sammy’s”, 82.13.31.123, 1402341603)
# (“sammy’s”, 82.14.34.125, 1402341513)
# (“osha thai”, 92.13.14.12, 1402341523)
每5秒钟收到新消息,调用process_message。要实现一个函数business_name返回10分
钟内出现次数最多的business_name。
# refresh time: 5 seconds
# window: 10 minutes
#
# def process_message(message):
# pass
#
# def business_name():
# pass | z*******o 发帖数: 4773 | | j**********3 发帖数: 3211 | | e***i 发帖数: 231 | 4 Yahoo?
Yelp?
YellowPage?
Yo?
YouTube? | t**r 发帖数: 3428 | 5 每个访问者维护一個queue. 每次访问往queue里加add。 每5秒pop所有的queue一次.
queue最长的就是了 | l******s 发帖数: 3045 | 6 seems similar to LRU cache
maintain a hashmap and listnode<{business_name, timestamp[]}, count =
timestamp.count>
at every refresh:
1. add or insert new node to a node in timestamp[] from message stream
2. traverse each node to remove timestamp of 10 mins ago (timestamp is a
sorted array)
3. on event of adding/inserting/removing timestamp, move node to sorted
position.
Plus: use ReaderWriter to make sure thread safe | t*8 发帖数: 14 | |
|