Amazon Interview Question for Software Engineer / Developers


Team: RCX
Country: United States
Interview Type: In-Person




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

Its a classic anagram check problem with a twist. Assuming that the letters are alphabets, you can declare a integer array of size 26, increment the character count as you scan the note. Decrements the count as you scan the magazine. Finally when you scan the character count array, it should have values >=0

- CSPrasad January 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

we can use Hash for storing the character as key and value as number of occurrences and keep on incrementing for note and decrementing for magzine

- CareerCupUser1 January 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

This question is actually available as a Video Interview on careercup.com

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

This is a classic question. Been asked this in at least 2 interviews.

- eugene.yarovoi January 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Create an array of the size of the domain of the note (i.e. smallcase and uppercase letter, punctuation, numbers etc, i.e. ascii search space of 256 characters).
Populate the respective array cell with the number of occurences of that element in the note.
Now read the magazine and decrement the respective cell count by 1 when you encounter that element in magazine.
Also, keep a global counter of number of distinct elements which have a current count > 0. Hence as soon as the count of an element decrements to 0, decrement the global counter as well (This will help in avoiding unnecessary further reading of the magazine even after all the elements of the note have been found in magazine).

- Learner January 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If the domain is words, that could be a somewhat larger space than you might hope.

- eugene.yarovoi January 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

solution at the granularity of words
create a trie out of the magzine string with the occurrences of each of them and try to find the strings in the note in the trie, if you find the string in the trie then reduce the occurance of that string by 1(since its cut paste not copy paste)...in this way if we could find all the strings then the kidnapper wins!

- raja roy January 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Cant we create a multidimensional string for both the ransom not and magazine.
Let the total no. of words present in magazine and note be m and n respectively.
then we are going to look for the first string in multidimensional string from note and search(binary) it in multidimensional string from magazine.
In this way we can search for each string present in note whether it is present in magazine.
Complexity will be logm X logn....

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

Cant we create a multidimensional string for both the ransom not and magazine.
Let the total no. of words present in magazine and note be m and n respectively.
then we are going to look for the first string in multidimensional string from note and search(binary) it in multidimensional string from magazine.
In this way we can search for each string present in note whether it is present in magazine.
Complexity will be logm X logn....

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

But we have to consider the case that whether a string such as"THE" or 'A' is not used more times in note than in magazine.
Then we have to keep count for each string also.
And for binary search we will have to do sorting of strings also.

- Hector January 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

find the LCS(longest common subsequence) . If the length is equal to that of the note then it contains

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

Seriously, what is it with everyone trying to use LCS for everything? LCS is a relatively inefficient algorithm (quadratic) at best, and incorrect in most problems, like this one, since the words can appear in a different order in the magazine than they do in the ransom note.

Remember, LCS is applicable in a relatively narrow range of situations.

- eugene.yarovoi January 08, 2012 | Flag


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