All Unique Permutations

Given a collection of numbers that might contain duplicates, return all possible unique permutations.

Example :
[1,1,2] have the following unique permutations:

[1,1,2]
[1,2,1]
[2,1,1]

NOTE : No 2 entries in the permutation sequence should be the same.

Warning : DO NOT USE LIBRARY FUNCTION FOR GENERATING PERMUTATIONS.

Example : next_permutations in C++ / itertools.permutations in python.
If you do, we will disqualify your submission retroactively and give you penalty points.

Interview Code Editor
1710 successful submissions.
Asked In:
  • Microsoft
  • Facebook
  • Google
Click here to jump start your coding interview preparation