I have an array of integers 1<=N<=100
, How can I get permutations of this array? Array may contain duplicates, so resulting set of permutations can be duplicate, so need to get all non-duplicate permutations.
- I've found lot of snippets which would convert the
int[]
to string and perform permutations and printout, but as I hv here is integers of range1<=N<=100
, so converting them into string would spoil integer. - I can get all permutations with duplicates including, for final set of permutations where duplicates are removed have to check with each other to remove a duplicate or so, it so heavy process.
Is there any simpler way?
For example, 123
would give:
231
321
312
132
213
123
Similarly for 112
program would give:
121
211
211
121
112
112
So, for n
-set of elements, permutations will be of n!
With duplicates in elements, would decrease tht.
I'm asking how can I remove those duplicate sets. (duplicate set of permutation arr[])