Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order.
Example 1
Input: nums = [1,2,2]
Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
Explanation: The two 2s are identical, so choosing either one alone gives the same [2]. Counting each distinct subset once gives 6: [], [1], [2], [1,2], [2,2] and [1,2,2].
Example 2
Input: nums = [4,4,4,1,4]
Output: [[],[1],[1,4],[1,4,4],[1,4,4,4],[1,4,4,4,4],[4],[4,4],[4,4,4],[4,4,4,4]]
Explanation: There is one 1 and four 4s. A subset can include 0 or 1 copies of 1 and between 0 and 4 copies of 4, giving 2 × 5 = 10 distinct subsets.
Example 3
Input: nums = [0]
Output: [[],[0]]
Explanation: A one-element array has two subsets: [] and [0].
Sort so equal numbers are adjacent, then during backtracking skip a value that equals its left neighbor at the same recursion depth — that branch was already taken.
Run checks all cases above. Submit evaluates all test cases.