Amazon Interview Question for Interns


Country: United States
Interview Type: Phone Interview




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

How do you check if a word is valid or not ?? meaning how to validated if "dad" , "daddy" is valid word ?

- Mr.karthik.p March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Greedily solving 1D subproblem will not work. See counter example below.

dadzzzz
dadzzzz
dadzzzz
azzzzzz
dzzzzzz
dzzzzzz
yzzzzzz

if i do row first

i will get 3 dad = 9

but i could get 2 dad and daddy vertical
= 11

- draftse March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Isn't the counter-example invalid?
When deciding the fate for char[2,1] (zero-based), putting it as part of the row yields 3 characters used and putting it as part of the column puts usage as 5 characters used - the greedy choice in this example points to the optimal solution.

- inosvaruag March 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

How do you find all words in an 1D array using Dynamic programming in linear time?

- gyg March 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you cant solve it in linear time ..it will O(n^2) for 1D array .

- Mr.karthik.p March 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

In 1D array you can find all strings in O(n) time - e.g. by Aho-Corrasic automaton. Via dynamic programming this is O(n^2). This is not the "hard part", the optimization problem will be interesting..

- tpcz March 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I agree. it will be O(n^2) sorry for the confusion.

- Anonymous March 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

who can write the algorithm for 1D array, and mark which letter has been used to compose a word? Use as many letters as you can?

- Bin March 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Me, Me!

- EK MACHCHAR May 05, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assume you have a constant look up for isword()

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

this algorithm seems correct to me, for a 1-d array
1. scan the string and find the first word
2. split the string into the first word and letters preceding it and letters following the first word
3. then the longest word is either the first longest word found or recursively solve the other two subproblems.
4. repeat this procedure for the next word and so on (hence dynamic)

- nikaash July 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i mean first word, first longest word doesn't make much sense

- nikaash July 05, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

take the 2-d array and parse it completely and store all the characters in an unordered multimap, say if a occurs at row 2 and row 5 then store {a,2}, {a,5} in the map. Now start from first row, 'check' all the rows that have common characters with this row and then proceed to the next 'unchecked' row and do the same. O(n^2) space and O(n^2) time

- sassy1 February 21, 2014 | 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