Google Interview Question for SDE1s


Team: google map
Country: United States




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

To generate friend suggestions, for a person in the graph find all the friends connected to this person(1-HOP) then suggest the friends of these friends(2-HOP).
We can refine this more by suggesting 2-HOP friends who have common attributes like same school, same subject of interest, etc.. so on to order the suggested friends list.

I guess it would be better to store connected nodes(friends) in the graph on the same server machine since there is a high chance that friends will want to see updates from friends. Though some nodes on the friends graph will be redundant on more than one machine.

- Subhajit June 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

we have only 'friendship' graph not there likes,schools or other

- niraj.nijju June 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

we have only 'friendship' graph not there likes,schools or other
here my pseudo code

Let we need to suggest for niraj.nijju(a user).

Set firstOrderFriend = getFriendsList(niraj.nijju);
Set<Friend, Integer> secondOrderFriend;

for(Friend aFriend: firstOrderFriend){
  Set tempList = getFriendsList(aFriend);
  for each Friend atempFriend in tempList{
    if(firstOrderFriend.contains(atempFriend))
      continue;
    if(secondOrderFriend.contain(atempFriend)){
       secondOrderFriend.put(atempFriend,secondOrderFriend.get(atempFriend)+1);
    else
       secondOrderFriend.put(atempFriend,1);
  }
}

Sort secondOrderFriend on basis of the Integer value(count of common friend)

Suggest the first n friends from secondOrderFriend

- niraj.nijju June 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
2
of 2 votes

OK I got that there are no likes, schools, etc..
In that case, ordering the suggested friends would be finding the common number of friends.

- Subhajit June 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

It always helps when you explain the code that you write on forums.

- Java_helps_you_unlearn June 13, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice solution.. but secondOrderFriend should be a Map (HashTable) since Sets don't get values

- niki November 15, 2013 | Flag
Comment hidden because of low score. Click to expand.


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