Skip to content
Veltoryx Technologies
ProProblem 84● MediumLeetCode #47 ↗4 min readUpdated 30 October 2026

Permutations II

Generate all unique permutations of an array containing duplicate numbers using duplicate neighbor pruning.

01The problem

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

InputOutputWhy
nums = [1, 1, 2][[1, 1, 2], [1, 2, 1], [2, 1, 1]]3 unique permutations (instead of 3! = 6)
nums = [1, 2, 3][[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]Distinct numbers case

Constraints: 1 <= nums.length <= 8, -10 <= nums[i] <= 10.

Loading the rest of the lesson…