Facebook | Phone | Simple spell checking engine

As per Glassdoor this was asked in recent Data Engineer phone interview. I.e Easy & Expected to be done in < 10 min.
I really can't think a way to do this under 10 min. Any pointers are much appriciated.
(Tipical DE interview will have 3-5 SQL & 3-5 Python question for an hour slot.)

The query language is a very simple regular expression-like language, with one special character: . (the dot character), which means EXACTLY ONE character (it can be any character). So, for example, 'c.t' would match 'cat' as the dot matches any character. There may be any number of dot characters in the query (or none).

Your spell checker will have to be optimized for speed, so you will have to write it in the required way. There would be a one-time setUp() function that does any pre-processing you require, and then there will be an isMatch() function that should run as fast as possible, utilizing that pre-processing.

There are some examples below, feel free to ask for clarification.

Word List:
[cat, bat, rat, drat, dart, drab]

Queries:

cat -> true
c.t -> true
.at -> true
..t -> true
d..t -> true
dr.. -> true
... -> true
.... -> true

..... -> false
h.t -> false
c. -> false
*/

// write a function
// Struct setup(List list_of_words)
// Do whatever processing you want here
// with reasonable efficiency.
// Return whatever data structures you want.
// This function will only run once

// write a function
// bool isMatch(Struct struct, String query)
// Returns whether the query is a match in the
// dictionary (True/False)
// Should be optimized for speed

Comments (9)