Google Interview Question for Software Engineers


Country: United States
Interview Type: In-Person




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

Model the problem as a graph and compute the minimum spanning tree.

- Anonymous February 03, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

what would be the weight of each branch?

- shing.zhao February 03, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

It's not gonna work.

Imagine that you were given a start network (each host is connected with all others, so the length of path from each to each is 1). If you'll build MST, in the worst case you'll get one path with length equals to n-1 (n is number of hosts).

- GK February 04, 2015 | Flag
Comment hidden because of low score. Click to expand.
-2
of 4 votes

At least I sparked some discussion ;)

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

MST won't cut. You need to compute all-pairs shortest path and store the relevant information in each of the nodes (if you know the nodes ahead of time).

- addlehead February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

MST won't cut. You need to compute all-pairs shortest path and store the relevant information in each of the nodes (if you know the nodes ahead of time).

- addlehead February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

In general the given graph is unweighted, because the cost of each edge is 1. So we have to solve the problem of shortests path.

It's not clear for me from task's description how are we gonna send packets: "any to any" or "specific to any".

For "specific to any" case it can be solved with BFS with remembering of previous vertex in the best path for each vertex. I think that you may perform the same idea for "any to any".

You also may use Bellman–Ford or Dijkstra algorithm.

- GK February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We need a bit more info, do we assume that Machine A sends a packet directly to Machine B without any intermediary devices? What does the network schema look like? How many routers/switches etc... are in between both machines? Does it cost $1.00 to send a packet to any one of these routers as well? A little bit more information on what we're dealing with would allow us to map out the network between the two machines and allow us to implement a cost minimizing algorithm.

Based on the initial question, I also believe that Djikstra or any other shortest-path algorithm is the way to go. MST won't work since all edges have the same weight.

- Anonymous February 04, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Make a graph containing all the machines as nodes and the edge weight as $1.00 .
Now try Dijkstra's algorithm with your position as source.

Dijkstra's algorithm is a single source shortest path algorithm but you can modify it for single destination also.

- Source February 05, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Run Dijkstra from the edge of the network. So each node knows the cost from it to send packets to all the edge.
Run Dijkstra from the starting node. So each node knows the cost from the start to itself.
Find the node that has the least cost and send packet to it and then distribute from there.

- Anonymous February 14, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here the network is slow and costly, we have to minimize the number of node we visit. Djikstra algorithm might be the best way to find the route

- sharukrules September 08, 2015 | 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