Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Design Search Autocomplete System
Bookmark
Brute Force
Trie + DFS
Pre-stored Top-3
Input
LeetCode Example
App Prefix
Hello Search
Custom
operations
=
[AutocompleteSystem, input, input, input, input]
,
values
=
[[["i love you","island","iroman","i love leetcode"],[5,3,2,2]],"i"," ","a","#"]
root
Operation
-
Input Character
-
Current Prefix
-
Top-3 Suggestions
-
Result
-
Default
Current
Visited
root
Operation
-
Input Character
-
Current Prefix
-
Top-3 Suggestions
-
Result
-
Default
Current
Visited
i
s
l
l
o
a
v
n
e
d
y
o
u
root
i
s
l
l
o
a
v
n
e
d
y
o
u
Operation
AutocompleteSystem
Input Character
-
Current Prefix
-
Top-3 Suggestions
-
Result
Inserted "island" (count: 3)
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input('i')
Input Character
'i'
Current Prefix
-
Top-3 Suggestions
-
Result
-
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input('i')
Input Character
'i'
Current Prefix
"i"
Top-3 Suggestions
1. "i love you" (5)
2. "island" (3)
3. "i love leetcode" (2)
Result
["i love you", "island", "i love leetcode"]
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input(' ')
Input Character
' '
Current Prefix
"i "
Top-3 Suggestions
-
Result
-
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input(' ')
Input Character
' '
Current Prefix
"i "
Top-3 Suggestions
1. "i love you" (5)
2. "i love leetcode" (2)
Result
["i love you", "i love leetcode"]
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input('a')
Input Character
'a'
Current Prefix
"i a"
Top-3 Suggestions
-
Result
-
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input('a')
Input Character
'a'
Current Prefix
"i a"
Top-3 Suggestions
-
Result
[]
Default
Current
Visited
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
input('#')
Input Character
'#'
Current Prefix
"i a"
Top-3 Suggestions
-
Result
count("i a") = 1
Default
Current
Visited
i
s
r
l
l
o
a
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
root
i
s
r
l
l
o
a
o
a
m
v
n
a
e
d
n
y
l
o
e
u
e
t
c
o
d
e
Operation
Done
Input Character
-
Current Prefix
-
Top-3 Suggestions
-
Result
All operations complete
Default
Current
Visited
algo
master
.
io
Step:
Initialize AutocompleteSystem
0 / 29
Input
LeetCode Example
App Prefix
Hello Search
Custom
operations
=
[AutocompleteSystem, input, input, input, input]
,
values
=
[[["i love you","island","iroman","i love leetcode"],[5,3,2,2]],"i"," ","a","#"]
0 / 29
algo
master
.
io
Step:
Initialize AutocompleteSystem