Amazon Interview Question for Software Engineer / Developers






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

You can build a suffix tree of both strings in O(N) and doing a depth first search, you can find the answer.

- Bala February 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Problem :
----------
Return the common string from 2 strings of arrays in optimal running time.


Example/Algo:
------------

S1{tarun}
S2{Varun}


R{arun}

Key Solution :
--------------
Compare the S1 1st char with S2 1st char
if not match then increment J
and continue matching till match is found.

Once match is found increment i & j till i!=j then break.


Code:
---------

Private string Returncommonstrg(String S1 , String S2)
{

For (int i=0 ; i<N-1 ; i++)
{
For (int j=0 ; J<N-1 ; J++)
{
char ch1 = S1[i];
char ch2 = S2[j];

if (Ch1==Ch2)
{
string result += S1[i];
i++;
}

}
}

Return result;

}

Order:
---------
O(N^2)

- Tarun Phaugat March 02, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

u ll still not know if thats the only substring or if there are more and bigger substrings...
so suffix tree is the way to go.. check it out in wiki

- clrs March 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

All that is there is :-
en.wikipedia.org/wiki/Knuth–Morris–Pratt_algorithm

- becga March 11, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

kmp does prefix matching not suffix

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

This is class dynamic programming problem..pls refer wikipedia for further details

- Neevan January 22, 2012 | 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