Given a collection of numbers, `nums`, that might contain duplicates, return all possible **unique permutations** in **any order**.
Example 1
Input: nums = [1,1,2]
Output: [[1,1,2],[1,2,1],[2,1,1]]
Explanation: Swapping the two 1s does not create a new arrangement, so of the 3! = 6 orderings only 3 are unique.
Example 2
Input: nums = [1,2,1]
Output: [[1,1,2],[1,2,1],[2,1,1]]
Explanation: The input holds the same numbers as [1,1,2], just in a different order, so it has the same three unique permutations.
Example 3
Input: nums = [2,2,1,1]
Output: [[1,1,2,2],[1,2,1,2],[1,2,2,1],[2,1,1,2],[2,1,2,1],[2,2,1,1]]
Explanation: Two 1s and two 2s can be arranged in 4! / (2! × 2!) = 6 unique ways.
Sort so equal values are adjacent. Backtrack picking one unused index at each depth. To avoid producing the same permutation twice, only use a duplicate value if its identical predecessor has already been used at this branch — this fixes a canonical order among equal values.
Run checks all cases above. Submit evaluates all test cases.