Amazon Interview Question for Software Engineer / Developers






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

The question does not say "find the path". Check if it is possible to do it. Create one array of the first characters and another of the last characters in the string. If there are n-1 matches (one character in the first and one character in the last need not match), then we can do the same. Simple!

- G May 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Creating the array of first and last chars is O(n)
Now matching the two arrays is O(n^2).
So total complexity is O(n^2)

- Appy July 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

creating the graph is O(N^2)

- R November 17, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

If we sort two arrays then the total complexity is even O(nlog(n)).

- Aleksey.M January 27, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Build a graph of the strings where string A has an edge to string B iff the last letter of A is the first letter of B. Then run the hamiltonian path algorithm on said graph.

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

The graph is directed graph.

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

Does a polynomial time alogorithm exists for finding hamiltonian circuits?

- KK May 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I believe finding hamilton circuits in a graph is an NP complete problem.

- KK May 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Creating two arrays with the first char & the last char = O(n) (Both arrays can be built at the same time by loading the first & the last char of every string. Do this for every string. This is proportional to the number of strings & hence O(n)).

Comparing the two arrays if exactly n-1 matches are present is again O(n). We dont need 2 loops. We can compare both arrays in a single step index-by-index. Hence, this is O(n).

So, total complexity is O(n) + O(n) = O(n).

O(n) is defenitely better than O(n^2). But, I'm not sure about the time complexity of Hamiltonian circuits.

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

I still need to work out the Hamiltonian solution but rest of the solutions proposed above would fail on following test set:

"aa", "eb", "bc"

- geek January 09, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't Hamilton Circuit a NP-Complete problem?

- Anonymous April 24, 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