由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - an interview question, find mode in a rolling window along data sequence
相关主题
An interview question of finding the median in a moving win (转载)algorithm question到底是什么东西?
an interview algorithm question about finding even occuring (转载)问个C++的问题
help!(math, optimization)请问一道面试题
A hedge fund interview questions (CS)Two interview questions from knight capital
[合集] 非线性优化问题求助! (转载)A question: how to prove iterated conditioning expectation
excel 问题求指教,要不要从了offer?
请教一个比较旧的算法题这句code什么意思?
GS structured credit group面试sparse linear Ax = b , 有什么好办法解 x ?
相关话题的讨论汇总
话题: data话题: window话题: hashtable话题: each话题: frequency
进入Quant版参与讨论
1 (共1页)
m****r
发帖数: 141
1
The interview has been done.
Give a sequence of data (with duplicates), move a fix-sized window along the
data sequence and find mode in the window at each iteraion, where the
oldest data is removed and a new data is inserted to the window.
I cannot find better solutions here.
My idea: Use a hashtable, key is the data, key's data is the frequency of
the data occuring in the window.
At the first iteration, iterate each data in the window and put it to the
hashtable, meanwhile cout the frequency of each data. After that, traverse
the hashtable and return the data with the highest frequency. For each
following iteration, search the oldest data in the hashtable and reduce its
frequency by 1 if it is in the hahstable if it becoms 0 use new data to
replace the old one. Otherwise, just insert the new data into the hahstable.
Traverse the table and return the mode.
It is O(n * m) where n is data seq size and m is window size. The drawback
is : The hashtable size is not fixed, it may have resize overhead. Each
iteration, the table has to be traversed, it is not effcient.
Is it possble to do it with O(n lg m) or O(n) ?
Any help is appreciated.
thanks
s**********r
发帖数: 8153
2
时间复杂度都出来了。。面的啥职位?
1 (共1页)
进入Quant版参与讨论
相关主题
sparse linear Ax = b , 有什么好办法解 x ?[合集] 非线性优化问题求助! (转载)
请问关于一个分部积分的问题excel 问题
database startup の 广告~ (不是骗子) (转载)请教一个比较旧的算法题
问个题GS structured credit group面试
An interview question of finding the median in a moving win (转载)algorithm question到底是什么东西?
an interview algorithm question about finding even occuring (转载)问个C++的问题
help!(math, optimization)请问一道面试题
A hedge fund interview questions (CS)Two interview questions from knight capital
相关话题的讨论汇总
话题: data话题: window话题: hashtable话题: each话题: frequency