Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Permutations II
Brute Force
Sort + Prune
Frequency
Example 1
All Distinct
All Same
Two Duplicates
Custom
nums
=
[1, 1, 2]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
(enumerating…)
dedupe repeated orderings with a seen set
result
0
(none yet)
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
(enumerating…)
dedupe repeated orderings with a seen set
result
0
(none yet)
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
(enumerating…)
enumerate every ordering of the positions
result
0
(none yet)
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
1
1
2
[1,1,2] is new — keep it
result
1
[1,1,2]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
1
2
1
[1,2,1] is new — keep it
result
2
[1,1,2]
[1,2,1]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
1
1
2
[1,1,2] already seen — skip
result
2
[1,1,2]
[1,2,1]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
1
2
1
[1,2,1] already seen — skip
result
2
[1,1,2]
[1,2,1]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
2
1
1
[2,1,1] is new — keep it
result
3
[1,1,2]
[1,2,1]
[2,1,1]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
2
1
1
[2,1,1] already seen — skip
result
3
[1,1,2]
[1,2,1]
[2,1,1]
nums
generate all n! orderings, keep the first of each
1
1
2
ordering
(enumerating…)
3 unique permutations
result
3
[1,1,2]
[1,2,1]
[2,1,1]
Step:
Generate every ordering; keep the first of each distinct permutation.
0 / 8
Example 1
All Distinct
All Same
Two Duplicates
Custom
nums
=
[1, 1, 2]
0 / 8
Step:
Generate every ordering; keep the first of each distinct permutation.