Google Interview Question
SDE1sTeam: google map
Country: United States
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
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.
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).
- Subhajit June 04, 2013We 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.