注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
楼主,刚刚结束liveramp的一电面试,怀着很忐忑的心情奉献上热辣面筋。一共三道题目
第一个是what‘s your most Challenging project?这个题目我答得不好,估计跪在这里了
第二道题目:纸牌问题,我答得比较好! 第三道题目:given 1 terabyte key-value data, how do you store them so that insert, find, delete operations can be very fast? 这个问题我的回答是把这个大的file分成10,000份,then to the remainder that hashcode of each element modulo 10.000, we decide which element is in which small file。
如果有十台机器的话,先把这个big file 划分到10 台机器上,然后再载每台机器上划分成10,000份, 每一份再hash。
30份分钟的电面20分钟就结束了,我也感受到面试官Soerian的不耐烦。不管怎么样吧,这个公司我都好好的准备了,希望接下来其他公司的面试一切顺利吧。 下面是我自己总结的地里面一些liveramp题目的答案,希望造福后来者吧。
下面是six degree的题目答案:
We can treat the problem as a graph. Each person represents a node. and if two people are friends, there is a edge between the two nodes that represent them. The problem becomes that find the shortest path between two node: start node and end node.
We can adopt BFS, Dijkstra algorithm, Bidirectional BFS. |E| is the number of edges, and |V| is the number of vertex. 1 BFS runs in time O(|V| + |E|) 2 Dijkstra Algorithm with a priority queue runs in time O(|E| + |V|log|V| ) Since the weight of each edge in the search grap is same, Dijkstra algorithm will degenerate into BFS. Besides, it needs more data structre than BFS to implement it. For example, Dijkstra algorithm needs priority queue to keep track of every vertex and distance array to keep track of the distance from source vertex to other vertex. 3 Bidirectional BFS is better than BFS. I will talk about why Bidirectional BFS is better than BFS below. assume the distance between source to target is k, and the branch factor is B [every vertex has B edges]. BFS will open: 1 + B + B^2 + ... + B^k vertices. bi-directional BFS will open: 2 + 2B + 2B^2 + 2B^3 + .. + 2B^(k/2) vertices. for large B and k, the second is obviously much better the the first.
I will choose bidirectional BFS.
Algorithm idea: do a BFS search simultaneously from the source and the target level by level. (level 0 from source and target respectively , level 1 from source and target respectively....) The algorithm will end when the level from source meets the level from the target.
We will use the following data structures: 1 two queues to do BSF respectively from source and target node 2 we need class Node to represent every node in the graph. Class Node { public String name; public ArrayList<Node> neighbors; // public ArrayList<Node> predecessors; // to keep track of predecessors of every node in order to construct the shortest path after Bi- BFS public boolean visited; // label the visited node public boolean visitedFromStart; //label the node that are visited from start node 出unique words 的数目?如果是1GB? hashset 1TB? 分布式系统design
下面是这道题目的我和朋友们讨论的答案:
思路1:把数据分块,对每块unique再把这些结果收集起来一起uniqiue
思路2: 根据STRING产生HASHCODE,再和总机器数量去余数,根据余数可以把一样的STRING都分配到一个小机器上,每台机器分组HASHSET 先把小集合里面重复的都去掉 汇总应该就可以了
assume we have n computers, then we scan the big file, and compute the hashcode of each string, then hashcode modulo n (the number of computers) , we get a remainder. according to the remainder, we assign the string to respective computer. after scan the whole file, each mechine will use a hashtable to count the number of unique string on that mechine. Then we add up the number from all mechines. and we get the total number of unique string.
If there are a lot of strings on one mechine, we can divide the strings into M chunks, for each chunk, we use a hashtable to find out the unique strings and put them into a file. then merge these small files into a big file. Then we do the same operation on the big file recursively until there are no duplicates and we count the number.
思路3: 1. 采样1% string,数据大的话实际上0.1%也成,排序。2.把这个排序的文件分成n份,记录下分点上的string。3.处理源数据,分成m块,每块uniq,然后对每个结果string,在2的结果上二分查找决定分到哪份,写下去
step 1 we take some sample strings from the big file. for example ,one percent or zero point one percent (0.1 %) if the file is too big. Then we sort the sample strings.
step 2 we divide the sample strings into N intervals
step 3 we divdie the big file into M chunks, for each chunk we use a hashset to find out the unique strings. then for each unique string we use binary search to find its position in the smaple strings, put it into relitive interval.
step 4 we deal with the N intervals respectively. for each intervals we use a hashmap to find out the unique strings . Then we add up the number of unique strings in each interval and we get the total number of unique string.
翻纸牌问题的答案:
cards on the table, X, Y, 1, 2. . WEach card has letter on one side and number on the other side. . Given the statement "The number side of X is even", at least how many cards need to flip to prove/disprove it?
answer: we need to filp two cards, one is X card, the ohter is 1 card. if the other side of X card is odd, the statement is false. OR if the other side of 1 card is X, the statement is false. Otherwise, the statement is true;
投篮问题的答案:
投篮3个进2个,或者8个进5个算赢,问你选哪个
solutions:
according to the law of large numbers (LLN), the of the results obtained from a large number of trials should be close to the , and will tend to become closer as more trials are performed.
if your shooting probility is greater than 0.6 , I will choose ⅝. if you are not gooding at playing basketball, I will choose ⅔, and you got that result by chance.
以上这些题目的答案是我自己总结的,可能有不足的地方,仅供参考,也希望大家提出改进的意见。
anyway,我感觉自己很认真准备这家公司,最后还是fail了,希望其他公司的面试一切顺利吧。。。。PS,大家看在我这么认真和用心总结的份上,赏点大米吧。谢谢啦
|