Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Combination Sum III
Brute Force
Backtracking
Bitmask
Example 1: k=3, n=7
Example 2: k=3, n=9
Small: k=2, n=5
Larger: k=4, n=10
Custom
k
=
3
,
n
=
7
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
check every combination of 3 digits, keep sum = 7
result
0
(none yet)
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
check every combination of 3 digits, keep sum = 7
result
0
(none yet)
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[1,3,5] sum =
9
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[1,4,9] sum =
14
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[1,8,9] sum =
18
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[2,4,7] sum =
13
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[2,7,8] sum =
17
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[3,5,7] sum =
15
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[4,5,7] sum =
16
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
[5,6,7] sum =
18
≠
n 7
result
1
[1,2,4]
digits 1..9 · k = 3, n = 7
1
2
3
4
5
6
7
8
9
1 valid combinations
result
1
[1,2,4]
Step:
Check every combination of 3 digits from 1..9; keep the ones summing to 7.
0 / 86
Example 1: k=3, n=7
Example 2: k=3, n=9
Small: k=2, n=5
Larger: k=4, n=10
Custom
k
=
3
,
n
=
7
0 / 86
Step:
Check every combination of 3 digits from 1..9; keep the ones summing to 7.