Google Interview Question


Country: India




Comment hidden because of low score. Click to expand.
4
of 4 vote

For each node in the FB graph, first find all nodes which can be reached with a path of length 2 from our node. These represent friends of friends nodes. For our nodes, sort these nodes list by the maximum no of paths of length 2 via which we can reach a node. Say that I have 5 nodes in the list which I can reach via a path of length 2 from my node. Now, if I can reach one of these nodes(say 'C') via 6 different 2-paths, that means that C and I share 6 mutual friends. This node is given the highest priority of recommendation.

But, I think this way, we'll be storing way too much information for each and every node......a sorted list for each node....the length of which can go to thousands......

- Anonymous December 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

We can calculate the 2nd order of the adjMatrix, this would not only give the paths of length 2 but also the No of 2-length paths possible between i and j....

- Ashupriya July 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
4
of 4 vote

hmm.

For just Friends of Friends..

Do a BFS with slight change
when you reach a visited node again, instead of ignoring just increment the count, which indicates common friends. Keep a top 100 Priority Queue and keep adding whenever the count is more than the smallest in the queue.

Add other weightage factors now like,
same (ex-)company, same school, common group, same city etc.

- Anonymous December 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could this algorithm create an infinite loop?
Say a has a friend b who has a friend c who has a friend a.

- someone December 26, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

you only need to go to 2 levels deep, there should be no loop.

- bloggans January 23, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

also if c is a frnd of a, a is frnd of a too,indirect graph, so it will discovered at first and no loop

- Mohit April 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

To accomplish "Keep adding whenever the count is more than the smallest in the queue. ", you need to know/accumulate running counts of elements that are not in PQ. The best way to do that is to store non-top-100 elements too in the same PQ.

- jatin085 April 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hadoop it. Where Map is a query:
select T1.Friend from T as T1 where T1.Person in {select T2.Friend from T as T2 where T2.Person = "Name"} and T1.Person != "Name". The reduce function is the Union Function.

- Anonymous December 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It seems like graph problem.
1) Check if one node can be reached(friends) from more than one node then that will be highly recommended node.
2) Friend of friend will next recommendation. (Less priority than first).

Graphs can be made for one person in many ways.
1) Based on names.
2) Based on places.
3) Based on schools.
(All Parameters like places etc.)

- Dhiraj December 10, 2011 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More