You are given an integer array that may contain duplicate elements. Your task is to generate all unique subsets of the array.
The solution set must not contain duplicate subsets, even if the input has repeated values.
Example 1
Input: arr[] = [1]
Output: [] [1]
Explanation: Only the empty set and the single element subset are possible.
Example 2
Input: arr[] = [1 2 2]
Output: [] [1] [2] [1 2] [2 2] [1 2 2]
Explanation: Duplicate elements exist, but only unique subset combinations are included.
Example 3
Input: arr[] = [1 2 2 3]
Output: [] [1] [2] [3] [1 2] [1 3] [2 2] [2 3] [1 2 2] [1 2 3] [2 2 3] [1 2 2 3]
Explanation: Subsets are formed while avoiding repeated combinations caused by duplicates.
Sign in to write, run, and submit your solution against the full test suite.