R
E
A
C
T
O
xamples
epeat
ode
pproach
ptimize
est
{Dictionary Word Finder}
The Question
Given
- An alphabetical array of dictionary entries and
- A word to search for
find and return that word's definition (if it exists).
This array of dictionary entries will be formatted like so:
Example
insert 'a'
[ 'a' ]
What do you notice about the entires?
Naive Approach
(aka Brute Force)
insert 'a'
[ 'a' ]
- What is the bigO time complexity?
- Space complexity?
- Nice way to es6-ify this?
es6 Array.prototype.find()
insert 'a'
[ 'a' ]
- What is the bigO time complexity?
- Space complexity?
- Nice way to es6-ify this?
Optimized approach
insert 'a'
[ 'a' ]
What have we not taken full advantage of yet?
Optimized approach
Binary search
insert 'a'
[ 'a' ]
What next?
Optimized approach
Binary search
insert 'a'
[ 'a' ]
Optimized approach
Binary search
insert 'a'
[ 'a' ]
What is the time and space complexity?
Interviewer Tips
insert 'a'
[ 'a' ]
- Meet the interviewee where she is at.
- If time permits, try to help her optimize by asking her what piece of info has not been made use of.
- If that doesn't lead her to BS, ask her how SHE would look for a word in a dictionary.
- If time permits, try to lead her to pseudo-coding out a BS approach, then maybe coding it.
- If your interviewee goes down a rabbit-hole trying to implement a compareByAlphabeticalOrder function, just let her know that she can use '<' and '>' to compare strings.
- Please keep track of time, we will reconvene here at 10:15 and discuss the EVEN MORE optimized approach. 😯😮😲😀😎
Further Optimized approach
Hash maps
insert 'a'
[ 'a' ]
What is the time and space complexity?
Takeaways?
insert 'a'
[ 'a' ]
Approach | Time complexity | Space complexity |
---|---|---|
Takeaways?
insert 'a'
[ 'a' ]
Approach | Time complexity | Space complexity |
---|---|---|
Naive | O(n) | O(1) |
Binary Search | O(log n) | O(1) |
Hash Map | O(1) (first time O(n)) | O(n) |
What else did you learn from this problem?
What questions do you have?
Dictionary Word Finder
By mschreiber
Dictionary Word Finder
Technical interview problem on finding word definitions
- 815