Amazon Interview Question for Software Engineer / Developers


Team: Audible
Country: United States
Interview Type: Phone Interview




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

build a trie from the file
traverse the trie based on the pattern
if it is specific character, traverse the edge of that character
if it is _, traverse all edges

- dgbfs November 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

With this method you will need to be mindful of the length. So you need to keep track of it when traversing the tree

- M.Zimmerman6 November 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

well i think tries and suffix trees solve a lot of problems...can somebody suggest where can i get their c codes from? or plz a trie solution for this question..thanks

- guest January 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
2
of 2 vote

Well there are a few clarifications needed -
How big is the file?
Are the strings in file sorted?
Does "_" mean single character or multiple characters?

If big file and strings are not sorted and we are using this function a lot then it makes sense to make a suffix tree like structure.
If sorted then just need to reach that point using some variation of binary search.
If small file then maybe even using brute force way of searching may be benificial.

- Anonymous November 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

how many _ are possible?

- asd November 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Does underscore ('_') imply one character, or can it be multiple characters, including no character?

If the former, then scan the file for all 4 character words starting with H, having L as the 3rd character.

Building a trie will be rather expensive, not to mention that it may not all fit into memory in the first place. Building a distributed trie is possible to workaround this, but that infrastructure investment better be worth the returns on it.

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

I agree with distributed trie solution if the size of file is big.
Also its one time effort to construct trie with future gain in search.
Also usage of suffix tree, is further addon over trie.

- ashu November 20, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Python Example using RegEx:

import re
all_words = ["HELL", "HILL", "HELP", "HALF", "NINE", "HELLO"] # Sample Words

def findMatches (search_string):
  return [x for x in all_words if re.match (re.sub ("_", ".", search_string) + "$", x)]

matches = findMatches ("H_L_")
print matches

- Kyle November 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

sd

- Karthik November 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{ String str = getString();
String []strarr = {"HELL", "HILL", "HELP", "HALF", "NINE", "HELLO"};

str = str.replace("_",".{1}");
str = "^" + str + "$";
System.out.println(str);

for(int i = 0; i<strarr.length; i++)
{
if(strarr[i].matches(str))
System.out.println(strarr[i]);
}
}

- Karthik S November 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using Python
words=['help','hell','bug','hale','gale']
s="h_l_"

for w in words:
if len(w)!=len(s):
print '%s does\'t match'%w
else:
match=True
for i in range(len(s)):
if s[i]=='_':
continue
else:
if s[i] != w[i]:
match=False
break
if match:
print '%s matches'%w
else:
print '%s dosn\'t match'%w

- Anonymous December 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Scala:

Assuming the words have been read into a List:

def getPossibleSolns(words: List[String],r: Set[String]): Set[String] = words match {
 case Nil => r
 case head :: tail => head.toList match {
  case 'H' :: _ :: 'L' :: _ => getPossibleSolns(tail,r+(head))
  case _ => getPossibleSolns(tail,r)
 }
}


val xs = List("HOW","WHAT", "HELP", "WHERE", "HELD","HOW","HELL")

val r = getPossibleSolns(xs,Set())

scala> val r = getPossibleSolns(xs,Set())
r: Set[String] = Set(HELP, HELD, HELL)

- rbsomeg February 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

We can use shell scripting... Such kind of pattern searching is much easier in scripting language.

- Varun November 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Varun: if you really want to do the pattern search then you can also use regular expressions (in Java, C#), In that case programatically creating the pattern itself will be the only tough part. personally i liked the trie way assuming you don't have any APIs (which is what the interviewer must be expecting)

- The Artist November 20, 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