Amazon Interview Question


Country: India
Interview Type: In-Person




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

I believe this might be solvable if we view the decisions for the crossword as a tree and do DFS.

Every time we assign a certain word to a certain position, that corresponds to arriving at a node. Any subsequent decisions after this can be viewed as children of this node. The children of this node would need to satisfy two constraints:
1. Required length
2. Same character positions in the word when touching other words already present.

DS for dictionary
1) 1-D array of linked lists where ith row contains all the words which have length i+1
or
2) 2-D array [26][variable length array] of linked lists where [i],[j] contains a list of all words for which i+1'th alphabet lies in position j.

Based on the choice of either data structures, one needs to perform an additional check on character position and length respectively.

Now one can continue traversing the tree till the tree reaches depth of N where N is the total number of words to be filled in crossword.

- inosvaruag January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

what is the time complexity you are up to ?

- Anonymous January 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hari
Interviewer told you to write a code or only algo ?

- NoMind January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just to get mailers about this problem :-)

- Nitin Gupta January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

this problem and the idea for solution can be found in the famous book "Etudes for Programmers" by Charles Wetherell. The book suggests 4-man-weeks estimate to write the completed code for the solution + 1 week for graphics output O_o
Minor note: The problem input description that was sent here is missing the direction of to-be-filled word(horizontal or vertical)

- S.Abakumoff January 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use a Trie data structure for this problem.

- A January 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Patricia for storing the dictionary.

Do we need to solve the crossword? or just fill it?

- mathura January 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think a suffix array/suffix tree would be a good data structure to solve this

- Ravi February 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use an adjacency graph to depict dependencies of words with other words. Once we have a graph, we can start with any node, Get a set of words which match the 'local' constraint, select any one word and traverse all neighbors by DFS (BFS will work too) . We will have to perform backtracking if any of the nodes fails to get a word among the set of words. We have to keep in mind that this is a graph and can be cyclic. There should be an ending condition where all the nodes satisfy the constraints.

- Ace February 17, 2013 | 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