cheetcode

74. Subsets IIMedium

Return every unique subset when the input may contain duplicate values.

Given an integer array that may contain duplicates, return all possible unique subsets.

The runner accepts the subsets in any order.

Build one partial choice at a time, recurse, then undo that choice before exploring the next option. Pay close attention to duplicate handling and stopping conditions.

Examples

Input: nums = [1,2,2]
Output: [[],[1],[2],[1,2],[2,2],[1,2,2]]
Input: nums = [0]
Output: [[],[0]]

Constraints

  • 1 <= nums.length <= 10
  • -10 <= nums[i] <= 10