Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Word Pattern
Bookmark
Two Hash Maps
Index Mapping
Input
Match
Letter clash
One letter, many words
One word, many letters
Custom
pattern
=
abba
,
s
=
dog cat cat dog
pat
s
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
(no bindings yet)
build a two-way letter ⇄ word mapping as you scan
pat
s
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
(no bindings yet)
build a two-way letter ⇄ word mapping as you scan
pat
s
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
(no bindings yet)
len(pattern)
4
=
4
words
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
(no bindings yet)
letter
a
free to map
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
bind
a
⇄
dog
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
letter
b
free to map
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
b
⇄
cat
pattern[2] =
b
word =
cat
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
b
⇄
cat
word
cat
maps to 'b'
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
b
⇄
cat
pattern[3] =
a
word =
dog
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
b
⇄
cat
word
dog
maps to 'a'
pat
s
i
a
b
b
a
dog
cat
cat
dog
0
1
2
3
map
a
⇄
dog
b
⇄
cat
return
true
algo
master
.
io
Step:
Each letter must map to exactly one word, and each word back to one letter
0 / 19
Input
Match
Letter clash
One letter, many words
One word, many letters
Custom
pattern
=
abba
,
s
=
dog cat cat dog
0 / 19
algo
master
.
io
Step:
Each letter must map to exactly one word, and each word back to one letter