Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Letter Combinations of a Phone Number
Iterative BFS
Backtracking
Example 1: "23"
Single Digit: "2"
With 4-letter keys: "79"
Three Digits: "234"
Custom
digits
=
23
digits
2
3
combos (1)
""
extend every combo by each letter, digit by digit
digits
2
3
combos (1)
""
extend every combo by each letter, digit by digit
digits
2
3
a
b
c
'2' → abc
current combos (1)
""
next (0)
(building…)
extend all 1 combos by "abc"
digits
2
3
a
b
c
'2' → abc
current combos (1)
""
next (2)
a
b
"" + 'b'
digits
2
3
a
b
c
'2' → abc
current combos (1)
""
next (3)
a
b
c
"" + 'c'
digits
2
3
d
e
f
'3' → def
current combos (3)
a
b
c
next (1)
ad
"a" + 'd'
digits
2
3
d
e
f
'3' → def
current combos (3)
a
b
c
next (3)
ad
ae
af
"a" + 'f'
digits
2
3
d
e
f
'3' → def
current combos (3)
a
b
c
next (5)
ad
ae
af
bd
be
"b" + 'e'
digits
2
3
d
e
f
'3' → def
current combos (3)
a
b
c
next (6)
ad
ae
af
bd
be
bf
"b" + 'f'
digits
2
3
d
e
f
'3' → def
current combos (3)
a
b
c
next (8)
ad
ae
af
bd
be
bf
cd
ce
"c" + 'e'
digits
2
3
result (9)
ad
ae
af
bd
be
bf
cd
ce
cf
9 combinations
Step:
Extend every partial combination by each letter, one digit at a time.
0 / 16
Example 1: "23"
Single Digit: "2"
With 4-letter keys: "79"
Three Digits: "234"
Custom
digits
=
23
0 / 16
Step:
Extend every partial combination by each letter, one digit at a time.