Subsets II

Given an integer array nums that may contain duplicates, return every distinct subset, including the empty subset. Each indexed occurrence may be selected at…

Given an integer array nums that may contain duplicates, return every distinct subset, including the empty subset. Each indexed occurrence may be selected at most once. Equal values may appear together only as many times as they occur in nums. Return each resulting value-multiset once; order within rows and among rows does not matter.

- 1 <= nums.length <= 10. - -10 <= nums[i] <= 10. - Duplicates are allowed in nums, but duplicate result subsets are forbidden.

Example 1: input nums = [1,2,2]; output [[],[1],[1,2],[1,2,2],[2],[2,2]]. Choose zero or one copy of 1 and zero, one or two copies of 2: two times three gives six distinct subsets.

Example 2: input nums = [-1,0,0]; output [[],[-1],[-1,0],[-1,0,0],[0],[0,0]]. There are two choices for -1 and three multiplicities for zero. Equal zero occurrences do not duplicate result rows.

Example 3: input nums = [0]; output [[],[0]]. Choose zero occurrences to obtain [] or one occurrence to obtain [0]; each appears once.

Category: Recursion. Topic: recursion. Difficulty: Medium. Patterns: backtracking.