Microsoft Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

I would start with friends of friends as potential suggestions. These can all be retrieved by a breadth-first search restricted to a depth of 2. In that same breadth-first search, I would also calculate how many of the user's friends know each potential suggestion and rank the suggestions by this number. Simply put, if you're not friends with someone who is friends with 30 of your friends, that's usually a better person to recommend to you than someone who is friends with only one person you know.

We could modify the approach above to be more likely to recommend people that are friends with people you interact with a lot. The BFS would be the same, but the ranking algorithm could, instead of giving each potential suggestion 1 ranking point per mutual friend, vary the points based on how much you interact with the mutual friend.

We might consider being less likely to recommend friends that have been recommended recently and were not added by the user. We might also throw in some element of chance to give lower-ranked recommendations the possibility of showing up occasionally.

We might also consider removing from recommendations people you've un-friended in the past. People that you've blocked definitely shouldn't show up.

I'm sure Facebook's recommendation system is a lot more complicated than that and probably considers tens or hundreds of factors. It might even use machine learning to learn the factors that are most likely to make users add the people recommended to them. These are just some starting thoughts.

- eugene.yarovoi April 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

We could use Graph Transitive closure property. Which says if A is friends with B and B is friends with C, then A is friends with C. C would be our suggestion to the user. We can come u with a Connection Adjecency Matrix which can be written as

Connec[i][j] = Connection[i][j] | (Connect[i][k] && Connect[k][j])

For a user I we can suggest all the connections J which are already not in its list.

- CodeNameEagle April 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Fixed indention in above post!

Class Person {
    string name;
    string id;
    list <School*> schools;
    list<Company*> companies;
    list<Person*> friends;
    list<Location*> places;
}

list<Person*> FacebookSuggest(Person *p) {
    list<Person*> suggestedFriends;
    list<Person*> visitedFriends;
    list<Person*> toVisit;
    toVisit.push_back(p);
    
    while (!toVisit.isEmpty() {
        Person *person = toVisit.pop_front();
        foreach(friend in p.friends) {
            if (!visitedFriends.contains(friend)) {
                toVisit.push_back(friend);
                visitedFriends.append(friend);
                bool added = false;
            
                foreach(school in p.schools) {
                    if (p.schools.contains(school) {
                        suggestedFriends.append(friend);
                        added = true;
                        break;
                    }
                }

                if (added) {
                    break;
                }

                foreach(place in p.places) {
                    if (p.places.contains(place) {
                        suggestedFriends.append(friend);
                        added = true;
                        break;
                    }
                }
                 
                if (added) {
                    break;
                }

                foreach(school in p.schools) {
                    if (p.schools.contains(school) {
                        suggestedFriends.append(friend);
                        break;
                    }
                }
            }
        }
    }
  
  return suggestedFriends;
}

- Xyz March 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

We can use graph and and BFS to suggest friends.

Class Person {
    string name;
    string id;
    list <School*> schools;
    list<Company*> companies;
    list<Person*> friends;
    list<Location*> places;
}

list<Person*> FacebookSuggest(Person *p) {
    list<Person*> suggestedFriends;
    list<Person*> visitedFriends;
    list<Person*> toVisit;
    toVisit.push_back(p);
    
   while (!toVisit.isEmpty() {
        Person *person = toVisit.pop_front();
	foreach(friend in p.friends) {
            if (!visitedFriends.contains(friend)) {
		      toVisit.push_back(friend);
		      visitedFriends.append(friend);
                       bool added = false; 
		       foreach(school in p.schools) {
                               if (p.schools.contains(school) {
                                    suggestedFriends.append(friend);
				    added = true;
				    break;
                               }
                        }
			if (added) {
				break;
			}
 			
			foreach(place in p.places) {
                               if (p.places.contains(place) {
                                    suggestedFriends.append(friend);
				    added = true;
				    break;
                               }
                        }
			if (added) {
				break;
			}

			foreach(school in p.schools) {
                               if (p.schools.contains(school) {
                                    suggestedFriends.append(friend);
				    break;
                               }
                        }
            }
        }
  }
  
  return suggestedFriends;
}

- Anonymous March 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Not sure if this is a good approach.. Essentially you end up suggesting every person on Facebook!

- GodOfCode March 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@godofCode.. you are right, we can have a depth parameter ..it should search only to certain depth..?

- manish March 31, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

There should be some sorting criterium (no. of friends in common, for instance). I wouldn't go deeper than 2 anyways.. (depth 6 is the maximum according to a known theory)

- GodOfCode March 31, 2013 | Flag


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