Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

without any precomputation not possible....
With precomputation use hashing to find if a path exists between two pairs.

- anil1in7 January 18, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

The precomputation will be a DFS for each starting point in the graph.

- kr.neerav January 19, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Directed acyclic graph is equivalent to strictly partial order sets.
This problem can be solved by pre-construct a Hasse diagram for divisibility.
Ex.

-----------------90 (Exit)
                /|\
               / | \
             6  10  9
             \  /\  /
              \/  \/
              /\  /\ 
             /   3  \
            2    |    5
             \   |  /
              \  | /
                \|/
                 1(Entrance)

After precompute this hasse diagram, for any given start point and end point, we just need to find the corresponding value of them, and check whether the end point value is divided by the start point value.

- ZhenyiLuo January 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you add formatting to your answer?

- DS January 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ZhenyilLuo Your solution seems pretty interesting. How will I do this incase the nodes does not numbers but have strings. How will I check the divisibility?

- ur2cdanger January 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@DS I just changed a little

- ZhenyiLuo January 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ur2cdanger This tree is an additional structure which represents the partial relationship. It does not matter what the node has. We can use a HashMap<DAGNode, Integer> to record the relationship.

- ZhenyiLuo January 20, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

The idea is interesting. How do we construct the hasse diagram for divisibility for such a large graph. Is there a way to dynamically generate the hasse diagram for divisibility.

- kr.neerav January 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Do a DFS on the graph until all nodes are visited so you end up visiting each node only once.

If you process each vertex after all of its edges have been visited, you can build up a list of endpoints for each node.

Below assumes a DFS function that calls processLate after all edges have been visited for a node.

void processLate(Vertex v)
{
  for (Vertex n : v.edges)
  {
    if (n.edges.size() == 0) // check for neighbor with no edges (endpoint)
    {
      v.ep.add(n); // add neighbor to list of endpoints for this vertex
    }
    else
    {
      v.ep.add(n.ep); // neighbor not an end point, but already processed so grab it's endpoints
    }
  }
}

With this precomputing, you only need to check if the endpoint is in the list of a given starting node.

- Dave January 20, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi all, I am just a newbie to this site.

For this question, can I find all connected components and assign each node a component id, then answer yes to a query if two nodes have the same component id and answer no otherwise?

Or I need to find out the path as well?

- entri January 27, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

oops, it's DAG...

- entri January 27, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

For DAG, then I would pre-compute DFS visiting time and finishing time for all nodes. Based on visiting time and finishing values of nodes in the pair, I think I can decide whether it has a path between them or not.

- entri January 27, 2014 | Flag
Comment hidden because of low score. Click to expand.


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