avatar
Facebook Phone Screen# JobHunting - 待字闺中
M*d
1
三个问题
1. Given a linked list, unsorted, determine the middle point of it;
2. Find the deepest common ancestor of two leaves in a binary search tree;
Do not traverse from the leaves. Instead, locate the node top/down.
How about finding the shallowest common ancestor of two leaves?
3. Given constant incoming requests, each associated with a unique key,
estimate the total amount of unique requests within a period of time.
The number of keys explodes the memory. Do not touch the disk. Rou
avatar
s*n
2
这第三个问题怎么答?

【在 M****d 的大作中提到】
: 三个问题
: 1. Given a linked list, unsorted, determine the middle point of it;
: 2. Find the deepest common ancestor of two leaves in a binary search tree;
: Do not traverse from the leaves. Instead, locate the node top/down.
: How about finding the shallowest common ancestor of two leaves?
: 3. Given constant incoming requests, each associated with a unique key,
: estimate the total amount of unique requests within a period of time.
: The number of keys explodes the memory. Do not touch the disk. Rou

avatar
s*t
3

一块一慢两个指针?
tree;
从root往下找,如果左边小右边大。common acestor应该是从root往下处于两者之间的
那个节
点。
啥叫做shallowest?难道不就是根节点么?
key,
time.
Rough
不理解。如果每个都是unique的,难道不是加一堆计数器就行了么?
如果要id可以重复的话可以用checksum之类的东西来缩短id吧。可以maintain一个hash
之类的
东西吧。

【在 M****d 的大作中提到】
: 三个问题
: 1. Given a linked list, unsorted, determine the middle point of it;
: 2. Find the deepest common ancestor of two leaves in a binary search tree;
: Do not traverse from the leaves. Instead, locate the node top/down.
: How about finding the shallowest common ancestor of two leaves?
: 3. Given constant incoming requests, each associated with a unique key,
: estimate the total amount of unique requests within a period of time.
: The number of keys explodes the memory. Do not touch the disk. Rou

avatar
f*r
4
Sampling, I suppose...
avatar
s*t
5
我来写一下吧
第一个:
1. Given a linked list, unsorted, determine the middle point of it;
class Node {
Node next;
int value;
}
int getMiddle(Node root){
Node fast=root;
Node slow=root;
while(fast!=null&&fast.next!=null){
slow = slow.next;
fast = fast.next.next;
}
return slow;
}
avatar
s*t
6
第二个:
2. Find the deepest common ancestor of two leaves in a binary search
tree;
从root往下找,如果左边小右边大。common acestor应该是从root往下处于两者之间的
那个节
点。
Node findAncestor(Node a, Node b, Node root){
Node c = root;
while(true){
if(c.value> a.value && c.value > b.value) c = c.left;
else if(c.value< a.value && c.value < b.value) c = c.right;
else break;
}
return c;
}
avatar
s*t
7
找了一个以前写的递归的
public int findLowestAncestor(Node root, int value1, int value2) {
if (root == null) return -1;

if (root.value > value1 && root.value > value2) {
findLowestAncestor(root.left, value1, value2);
}
else if (root.value < value1 && root.value < value2) {
findLowestAncestor(root.right, value1, value2);
}
else return root.value;
}
avatar
s*n
8
我问的就是第三个问题。。。。。:P

【在 s******t 的大作中提到】
: 找了一个以前写的递归的
: public int findLowestAncestor(Node root, int value1, int value2) {
: if (root == null) return -1;
:
: if (root.value > value1 && root.value > value2) {
: findLowestAncestor(root.left, value1, value2);
: }
: else if (root.value < value1 && root.value < value2) {
: findLowestAncestor(root.right, value1, value2);
: }

avatar
t*t
9
bloom filter check the uniqueness of the key?

【在 s***n 的大作中提到】
: 我问的就是第三个问题。。。。。:P
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。