由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - An Old Question -- Top N Occurance Frequance
相关主题
leetcode 129拓扑排序
word ladder ii 谁给个大oj不超时的?G家电面(已挂)
菜鸟 贴一个 leetcode LRU Cache -- java代码,并求解疑惑。Some coding problems from Amazon
分别用LinkedList和HashMap构建字典树(Compact Trie)怎么做sorted linked list里insert一个node
Clone graph很可能被这题搞挂了,sort linked list
求帮忙看看这个clone graph的解法。弄半天还是不对。 多谢!在版上看到的G题
面试题:Data structure to find top 10 search strings有没有人面过citrix?顺便也求网上面试经验
Tripadvisor面筋FB第二轮电面记录
相关话题的讨论汇总
话题: node话题: question话题: occurance话题: linked话题: top
进入JobHunting版参与讨论
1 (共1页)
n*******s
发帖数: 482
1
Given a word stream, get the N words with top N highest occurance frequancy
(dynamically)
Any good approaches? Question is very open, try to explore the best space
and time complexity.
n*******s
发帖数: 482
2
Sorry, in office, can'te type chinese , just bare with my broken english
i would say
using a Hashmap to maintain the frequence for all words.
Value is defined as this
struct Node{
int key
int counter
struct Node* next;
};
struct V{
int counter;
struct Node* pt;
};
Also maitain a sorted list using Node as linked list (Olnly allow N nodes in the
linked list, the top N frequent words). The linked list is sorted.
When processing a word, first udpate the HashMap,
than, based on the V.counter to see if
(1) V.pt is already in the linked list, see if need to move the Node via to
a new place (since the counter is increaetd by 1, and we need to keep the
linked list sorted.)
(2) V.pt is none, and LinkedList is not full (<=N). Malloc a new Node and
linked to the sorted linked List
(3) V.pt is none and Linked List is full
if V.counter is greater than the Smallest Node in the Sorted LL
free the smallest Node and insert the a new Node with V's info.
update V.pt.
Worst Time Cost for each word processing is
O(1) --> hashMap lookup
O(N) --> maintain the sorted LL
O(1) --> to update the Node's Pointer in the hashmap, need another
lookup
But a lot of time is wasted on malloc/free.
i am also considering the change the LinkedList into a Mini-Heap. but the
heap operation will involve a lot of index udpate...i am a little hesitate
to do that.
1 (共1页)
进入JobHunting版参与讨论
相关主题
FB第二轮电面记录Clone graph
Second round phone interview with eBay求帮忙看看这个clone graph的解法。弄半天还是不对。 多谢!
问一题面试题:Data structure to find top 10 search strings
今天Amazon的phone interviewTripadvisor面筋
leetcode 129拓扑排序
word ladder ii 谁给个大oj不超时的?G家电面(已挂)
菜鸟 贴一个 leetcode LRU Cache -- java代码,并求解疑惑。Some coding problems from Amazon
分别用LinkedList和HashMap构建字典树(Compact Trie)怎么做sorted linked list里insert一个node
相关话题的讨论汇总
话题: node话题: question话题: occurance话题: linked话题: top