xamples
epeat
ode
pproach
ptimize
est
Given
find and return that word's definition (if it exists).
This array of dictionary entries will be formatted like so:
insert 'a'
[ 'a' ]
What do you notice about the entires?
(aka Brute Force)
insert 'a'
[ 'a' ]
insert 'a'
[ 'a' ]
insert 'a'
[ 'a' ]
What have we not taken full advantage of yet?
Binary search
insert 'a'
[ 'a' ]
What next?
Binary search
insert 'a'
[ 'a' ]
Binary search
insert 'a'
[ 'a' ]
What is the time and space complexity?
insert 'a'
[ 'a' ]
Hash maps
insert 'a'
[ 'a' ]
What is the time and space complexity?
insert 'a'
[ 'a' ]
Approach | Time complexity | Space complexity |
---|---|---|
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?