由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问道G题(3)
相关主题
least common ancestor的疑惑面google, fackbook前拿什么公司练手?
google onsite经历请教一个题Common Ancestor(不是tree)
微软电面题问个题:判断两个人是不是genetically related
G家电面面经--佛云了~~刚看了geekforgeek烙印代码果然一坨屎逻辑混乱
Ooyala这个公司如何呢?问Tarjan's Strong Connected Component中的
FLAG干货:报个Google电面面经
问一个树的题。报Google Offer并请教面试题
amazon面经,已挂。Facebook Phone Screen
相关话题的讨论汇总
话题: ancestor话题: descendant话题: bfs话题: person2话题: person1
进入JobHunting版参与讨论
1 (共1页)
s*****n
发帖数: 162
1
This is an old G onsite question about one year back.
Find a connection between two people if there is one, or return false.
Everyone has father and mother and the connection means if there are any
common relatives.
My idea is as following:
The relative social network should be represented as graphs instead of
binary trees. One way to solve this problem is to use BFS. Specifically, we
can do BFS for person1 and person2 for their ancestors/descendants
simultaneously. We can use a hashtable to record every ancestor/descendant
that find along the BFS. If a common ancestor/descendant is found or person1
/person2 is found to be person2/person1’s ancestor/descendant, then they
have a connection. If they do not have any common ancestor/descendant, then
return false.
I was wondering if there is any better solution?
l***i
发帖数: 1309
2
put an undirected edge from a person to his/her father, and one edge to the
mother. Then two persons are related iff there is a path from one person to
the other. You can do either bfs or dfs assume the graph is small enough.
Basically the connectivity problem.
b*******d
发帖数: 750
3
maybe just a common ancestor means there is a connection also?
1 (共1页)
进入JobHunting版参与讨论
相关主题
Facebook Phone ScreenOoyala这个公司如何呢?
问一个LCA问题FLAG干货:
Another problem about Binary tree.问一个树的题。
LCA 问题amazon面经,已挂。
least common ancestor的疑惑面google, fackbook前拿什么公司练手?
google onsite经历请教一个题Common Ancestor(不是tree)
微软电面题问个题:判断两个人是不是genetically related
G家电面面经--佛云了~~刚看了geekforgeek烙印代码果然一坨屎逻辑混乱
相关话题的讨论汇总
话题: ancestor话题: descendant话题: bfs话题: person2话题: person1