Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Subsets
Cascading
Backtracking
Bit Manipulation
Example 1: [1,2,3]
Example 2: [0]
Small: [1,2]
Three elements
Custom
nums
=
[1, 2, 3]
nums
1
2
3
start from [ [] ]; append each number to every subset so far
result
1/8
[]
nums
1
2
3
start from [ [] ]; append each number to every subset so far
result
1/8
[]
nums
1
2
3
result = [ [] ]
result
1/8
[]
nums
1
2
3
[] + 1 = [1]
result
2/8
[]
[1]
nums
1
2
3
take 2 → copy all 2 subsets and add 2
result
2/8
[]
[1]
nums
1
2
3
[] + 2 = [2]
result
3/8
[]
[1]
[2]
nums
1
2
3
take 3 → copy all 4 subsets and add 3
result
4/8
[]
[1]
[2]
[1,2]
nums
1
2
3
[] + 3 = [3]
result
5/8
[]
[1]
[2]
[1,2]
[3]
nums
1
2
3
[1] + 3 = [1,3]
result
6/8
[]
[1]
[2]
[1,2]
[3]
[1,3]
nums
1
2
3
[1,2] + 3 = [1,2,3]
result
8/8
[]
[1]
[2]
[1,2]
[3]
[1,3]
[2,3]
[1,2,3]
nums
1
2
3
8 subsets = 2^3
result
8/8
[]
[1]
[2]
[1,2]
[3]
[1,3]
[2,3]
[1,2,3]
Step:
Start from [[]] and append each number to every subset so far.
0 / 12
Example 1: [1,2,3]
Example 2: [0]
Small: [1,2]
Three elements
Custom
nums
=
[1, 2, 3]
0 / 12
Step:
Start from [[]] and append each number to every subset so far.