Permutation of Elements
This is a classic set of problems that can be solved using Backtracking.
#
Type 1 Problem: Permutation of Distinct Elements#
Problem DescriptionGiven a collection of distinct integers, return all possible permutations.
#
Input[1,3,5]
#
Output[
[1,3,5],
[1,5,3],
[3,1,5],
[3,5,1],
[5,1,3],
[5,3,1]
]
#
Solution#
Type 2 Problem: Permutation of Elements (duplicates possible)#
Problem DescriptionGiven a collection of integers that might contain duplicates, return all possible permutations.
#
Input[1,1,5]
#
Output[
[1,1,5],
[1,5,1],
[5,1,1]
]