Amazon Interview Question for Software Engineer / Developers






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

Put the first string into a suffix tree of words and then find common substring and the same for the other file. But I don't how the hell to create a suffix tree and to find a substring

- perllove September 16, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

http://en.wikipedia.org/wiki/Longest_common_substring_problem

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

my code in java:
public class LCSS {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String s1 = "It is snowing and I want to drive home.";
String s2 = "It is snowing and I want to go skiing.";
String s3 = "It is hot and I want to go swimming.";
String len = find_lcss(s1, s2);
len = find_lcss(len, s3);
//System.out.println("The length of longest: " + len);
System.out.println(s1.replace(len, " "));
System.out.println(s2.replace(len, " "));
System.out.println(s3.replace(len, " "));

}

/**
* @param s1
* @param s2
* @return
*/
public static String find_lcss(String s1, String s2){
if(s1.isEmpty() || s2.isEmpty())
return "";
int [][] table = new int[s1.length()][s2.length()];
int maxLen = 0;
int end_index = 0;

for(int i=0; i<s1.length();i++)
{
for(int j=0;j<s2.length();j++)
{
if(s1.charAt(i)!=s2.charAt(j))
{
table[i][j] = 0;
}
else
{
if(i==0 || j==0)
{
table[i][j] = 1;
}
else
{
table[i][j] = table[i-1][j-1] + 1;
}
}
if(maxLen < table[i][j])
{
maxLen = table[i][j];
end_index = i;
}
}
}
StringBuilder res = new StringBuilder();
for(int i =end_index+1-maxLen; i<end_index+1; i++){
res.append(s1.charAt(i));
}
return res.toString();
//System.out.println(end_index);
}
}

- newcup September 21, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Hi, the LCSS between 2 strings may be totally disjoint from LCSS of those 2 strings with a third string. So theres a need to find LCSS between each common SS of 2 strings & the third string.
for e.g.
abcderytlpr
abcdesytlpr
lmnopqxyttt
In the above the LCSS of first 2 is abcde, of all three is yt. So the above code needs to enhanced to account for this ?

- acoder September 21, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

create common suffix tree for all the files and each leave contains the info about which all file has that suffix.

check for the sentence with more than 3 word and which is longest and contains all the files info at its leave
(dont forget to store the position along with file at the leave)

- mail2vcp@gmail.com September 30, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Suffix tree is the way to go!

Just make sure that you know wherever you are encountering spaces because spaces will tell you boundaries of words and in turn boundaries of common sentences.

Click here to read a good tutorial on suffix trees www.math.tau.ac.il/~haimk/seminar02/suffixtrees.ppt

- loonyCoder October 25, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

How about this?
***********
i=1;
Nextword = firstWord;
do
{
pattern = file1;
do{
for(i=0;i<n;i++)
{
if(checkIfPatternInFile (pattern , file2)!=0)
break ;
}

if(i==n)
{
printf("common string is file1");
found = true;
break;
}
else
{
pattern = RemoveWordFromPattern(pattern, Nextword);
}
while(found == false && file1 has more than 3 words);

i++;
Nextword = LastWord;
}while(found == false && i<=3);
***********
Of course, i have not defined the functions, checkIfPatternInFile() and RemoveWordFromPattern(). But that should be relatively simple.

- Sudhir. October 29, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

why "It is" is not removed?

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

good catch!

- Anonymous May 06, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

"It is" is not removed because the fragment to be removed should be atleast 3 words . "It" " is" are only two words.

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

"It is" is not removed because the fragment to be removed should be atleast 3 words . "It" " is" are only two words.

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

"It is" is not removed because the fragment to be removed should be atleast 3 words . "It" " is" are only two words.

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

I think they are expecting 'diff' and text replace in file.. for this question..

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

may be you're right ! need to ask amazon guys, though !

- Anonymous September 25, 2009 | 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