15% off all plans & roadmaps Use code
See plansProblem editorial
Implement permuteUnique in the Solution class. The parameter nums contains integers, and a permutation is an arrangement that uses every element of nums exactly once.
Permutations II is a Backtracking Patterns problem, in the Permutations subpattern. The pattern covers subsets, permutations, combinations, N-Queens, and word search
The reference solution runs in O(n log n + n · P), where n is nums.size() and P is the number of distinct permutations. time and O(n) auxiliary space excluding the returned result, which itself requires O(n · P) space. space.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Permutations II is a Backtracking Patterns problem, in the Permutations subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.