Microsoft Interview Question for Applications Developers


Country: United States
Interview Type: Phone Interview




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

This is can also be done using two BFS searches - one from person A and one from person B.

BFS algorithm explores every node at a distance/radius k from the source node before it moves to distance k+1.  The algorithm also keeps a track of visited nodes by coloring them as white(not explored), gray(being explored) and black(explored).

Run two BFS searches from A and B:-
1.  From A, let the explored radius be X, let the colors used for exploration be g1 and b1
2.  From B, let the explored radius be Y, let the colors used for exploration be g2 and b2

Explore all nodes from A with X = 1, then from B with Y = 1, then from A with X = 2.. and so on.

During exploration whenever BFS from A encounters a node colored b2 or vice versa, the search can be terminated.

The degree of separation is X + Y.

- hmm December 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 5 vote

You can try this:
1) Create a graph between two people and their friends. If two people know each other (they are present in contacts list) make a vertex.
2) Find the shortest path between person A and B. Number of nodes in the path is the separation degree.

- thelineofcode December 14, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Finding shortest path can be done using Breadth first search.

- Anonymous December 15, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

1.first, we should make sure that A,B can be connected, that means there must be at least one path from A to B. we can use Union Find to check it(is root(A)==root(B)?).
2.second, if A,B are conntected, then use BFS to find the shortest path.

- busycai December 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

There is no concept of 'root' in a graph. To find out whether they are connected, you will have to use a graph traversal algorithm like BFS, with which you can find the shortest path as well.

- Anonymous March 04, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

What the degree of separation means? it is a distance on the graph?

- glebstepanov1992 December 17, 2013 | 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