BlackBerry

www.blackberry.com
Employer Engaged

Interview Question

Software Developer Interview

Given an input string and a dictionary of words, segment

  the input string into a space-separated sequence of dictionary words if possible. For example, if the input string is "applepie" and the dictionary is a standard set of English words, then we would return the string "apple pie" as output.
Answer

Interview Answer

2 Answers

0

Have a loop that that checks if the dictionary contains "a", if not, check if it contains "ap" and so on... when found in the dictionary, substring the input string starting from the character after the matched word.

Anonymous on Mar 16, 2013
0

I think there is a more complicated answer to this question. The difficulty of this question is that if the string contains words that if cut in the wrong place may turn the remaining part of the sting without a match from the dictionary. The best answer I know of for this question involves dynamic programming. Google it.

Anonymous on Nov 7, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.