Amazon Interview Question for Developer Program Engineers


Country: United States
Interview Type: Phone Interview




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

This is what my code looks like
public int countCommon(String A, String B)
{
int counter =0;
int j=3; int i=0;
String[] arr = A.split(" ");
while(i<arr.length){

while((i+j)<arr.length){
String compareTo="";
for(int k=i;k<(i+j);k++){
compareTo = arr[k] + " ";
}
if(B.indexOf(compareTo)!= -1){
counter++;
}
j++;

}
i++;
j=0;
}
return counter;

}

- Saurav April 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Saurav:

A few minor things but I think you should hash the strings and count them that way, so you can differentiate the different compared strings. like 'test', 'string', 'small' would have a count associated with it. Rather than returning an arbitrary number. Also I think compareTo = arr[k] + " "; should be something more along the lines of:

compareTo += arr[k];
if(k < arr. length())
compareTo+= " ";

Also you should not set j=0 at the end of the first while but set j=3...

And your if(B.indexOf(compareTo) != -1) { counter++; } should be a while loop because it only returns the first occurrence and not the total... Therefore you need to have a separate index to iterate along B.

A lot of this would be understood if you could write out your thought process rather than just coding without any comments.

- rdo April 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

garimaa.blogspot.in/2012/04/program-14th-in-c.html

- Solution April 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

spammer----------------

- Anonymous October 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The words in the examples are not successive!
If not need successive, we can use inverted list without postion, if need, we can use inverted list with position.
am I right?

- milo April 12, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can create hash list of all the words in list one. Then compare these words with list two.
So with complexity O(1) access time the prob can be solved.

- justakgupta April 12, 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