Amazon Interview Question for Software Engineer / Developers






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

Do a depth-first search starting at node A and ending at node B.

- Jack February 24, 2006 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can we do depth first search on graphs?

- Saumil May 26, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Associate or create a class for storing Distributor Center info
Lets call it DistCenter
Class called Edges
{
DistCenter1
DistCenter2
Weight
}

Hashtable indexed by the DistCenter

To store the graph
Create distCenter objects for each distribution center

For each DstCenter object A
Create a HashTable to store Edge objects
If there is an edge from this DistCenter to some other DistCenter B
Create the Edge object
initialize it with weight and the DistCenterObject references/pointers
Add the edge object to the Hashtable or map using DistCenter B as the Key

When done with all edges
Add the DistCenter,Edge Hashtable pair to the HashTable/ HashMap


How to calculate if there is a path or not

Below function will return the list of edges that contains the path information and weight and can be used to print the path with weights
It will return null if there is no path
List of Edges FindPath(DistCenter A ,DistCenter B)
{
Get List of Edges from HashTable for DistCenter A
if (List empty )
return null
else
return findCenter(List Of edges from DistCenter A, DistCenter B)


}

List of Edge findDistCenter(Hashtable of Edges, DistCenter B)
{
edge = HashTable of edges . get (DistCenter B)
if (edge != null )
return new edgeList .Add (edge)
else
for iterate for each edge in hashtable
do
HashTable edges= HashTable of distCenter .get (edge.DistCenter B)
edgeList = findDistCenter(edgeList,DistCenter B)
if (edgeList != null )
return edgeList.Add(iterator.edge)
done
return null
}

- lmp May 30, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can you explain why a Hash Table is better when we can use depth first search in the graph?

- Anonymous June 14, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think we can maintain the graph has an adjacency list. each entry in the adjacency list will have the reference to the node to which an edge exist and also the weight.

Example:
Struct Node{
Node *node;
int weight;
}
so each vertex will have the set of nodes to which it has an edge.
To perform a DFS on the entire graph would take O(m+n) then and you could still identify the path and the total weight of the path.

- Ram August 12, 2007 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

using bfs we always get the shortest path...

- Anonymous August 22, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Floyyd-Warshall Algorithm finds all-pair shortest path. u have to maintain just 2 matrix of size # of vertices X # of vertices.

- Dharam September 24, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Cant we not make a matrix type array
where all the distribution centers become the column and row names and the weight becomes the value inside the matrix. and if there is no path then it can somehow be represented by some special value
like maybe a negative number

- Dipin February 17, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use Adjacency List to represent the graph and run DFS or BFS to find out if there is a path between two nodes.

- gauravk.18 February 26, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i posted in wrong question.

- gattu April 20, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

disjoint set

- Anonymous December 02, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Graph representation and DFS

- MD March 04, 2010 | 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