I recently encountered this question in an interview and did pretty bad at it.
Setup:
Assume primitive Facebook. FB has Members.
class Member {
String name;
String email;
List<Member> friends;
}
Question: Code printSocialGraph(Member m). Direct friends of m are Level 1 friends. Friends of friends are level 2 friends.....and so on Print level 1 friends first. Then print level 2 friends....and so on
void printSocialGraph (Member m){
//Your code here
}
I tried to maintain a queue for storing the friends at each level but I did not get it very far. Any idea how we could go about solving it with all error checking conditions ?