Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Combination Sum II
Brute Force
Sort + Skip Dups
Frequency
Example 1
Multiple Dupes
Small
Custom
candidates
=
[1, 1, 2, 5, 6, 7, 10]
,
target
=
8
sorted candidates
0
1
0
1
0
2
0
5
0
6
0
7
0
10
try all 2^7 subsets, keep the first that hits 8
result
0
(none yet)
sorted candidates
0
1
0
1
0
2
0
5
0
6
0
7
0
10
try all 2^7 subsets, keep the first that hits 8
result
0
(none yet)
mask 12 of 127
0
1
0
1
1
2
1
5
0
6
0
7
0
10
[2,5] sum =
7
≠
target 8
result
0
(none yet)
mask 27 of 127
1
1
1
1
0
2
1
5
1
6
0
7
0
10
[1,1,5,6] sum =
13
≠
target 8
result
3
[1,2,5]
[1,1,6]
[2,6]
mask 41 of 127
1
1
0
1
0
2
1
5
0
6
1
7
0
10
[1,5,7] sum =
13
≠
target 8
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
mask 56 of 127
0
1
0
1
0
2
1
5
1
6
1
7
0
10
[5,6,7] sum =
18
≠
target 8
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
mask 70 of 127
0
1
1
1
1
2
0
5
0
6
0
7
1
10
[1,2,10] sum =
13
≠
target 8
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
mask 85 of 127
1
1
0
1
1
2
0
5
1
6
0
7
1
10
[1,2,6,10] sum =
19
≠
target 8
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
mask 99 of 127
1
1
1
1
0
2
0
5
0
6
1
7
1
10
[1,1,7,10] sum =
19
≠
target 8
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
mask 114 of 127
0
1
1
1
0
2
0
5
1
6
1
7
1
10
[1,6,7,10] sum =
24
≠
target 8
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
sorted candidates
0
1
0
1
0
2
0
5
0
6
0
7
0
10
4 unique combinations
result
4
[1,2,5]
[1,1,6]
[2,6]
[1,7]
Step:
Enumerate every subset; keep the first of each that sums to 8.
0 / 130
Example 1
Multiple Dupes
Small
Custom
candidates
=
[1, 1, 2, 5, 6, 7, 10]
,
target
=
8
0 / 130
Step:
Enumerate every subset; keep the first of each that sums to 8.