Amazon Interview Question for Software Engineer / Developers






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

tortoise and hare algorithm to detect circle.
then go reverse to find the beginning node.

- pansophism December 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Tortoise-hair is the best for finding loops in linked lists.
But for Graphs, i think we should do a BFS & check whether the visited node is visited again.

- Jegan Shunmugavel December 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the node is visited again, then its the start as well as end node of the loop. So, now the problem s to figure out the loop starting with the visited node.

- Jegan Shunmugavel December 15, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

or just use hashmap, insert into the map and wait for the first collision happen

- pansophism December 13, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

using dfs.. check if the graph has any strongly connected components. If it does, it has a cycle..

- dexter December 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think using dfs is good idea, till you reach the dead end check in your hashmap if node has been already visited.

- Ajay December 19, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@dexter
cn u pls write a pseudocode for this

- Anonymous January 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

DFS is the correct and optimal answer.
Initialise all nodes with white color
Visit a node color it grey, continue with its connected nodes
while doing so if u find the visiting node grey then the its cyclic

- akshaycmpn January 17, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I know that I might sound stupid for asking, but what do you mean by "WAP" at the beginning of the original post?

- Mike January 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I know that I might sound stupid for asking, but what do you mean by "WAP" at the beginning of the original post?

- Mike January 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

WAP -> Write a program

- Jeeper January 23, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we can use a modification of the kruskal's algorithm to find the minimum spanning tree.
We can set every node in the graph as an independent set and sort the edges
for every edge in the list we check if both the ends are in the separate set, if u=yes then we merge
If we encounter an edge whose both ends are already in the same end, then we found the cycle.

For set operations we can use a Union-find data structure

- ketz January 30, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Minimum spanning tree. Just do DFS, and assign each edge same weight (1). If the cost any time increase the maximum possible cost (all edges being traversed, there is a cycle.

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

DFS is the correct one.
Initialize all nodes with white color.
Visit a node, color it gret, continue with its connected nodes.
while doing so if u find the visiting node grey then the its cyclic.

- weijiang2009 February 06, 2011 | 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