Skip to content
BASA DSA

Subsets II

MediumBacktracking

Return all distinct subsets of nums, which may contain duplicate values. Include the empty subset and do not repeat equivalent multisets.

Example 1

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

Explanation

Choose zero or one 1 and zero, one or two 2s, giving six multisets.

Example 2

Input
nums = [0,0]
Output
[[],[0],[0,0]]

Explanation

Equal zeroes give only [], [0], [0,0], without duplicate singletons.

Example 3

Input
nums = []
Output
[[]]

Explanation

The empty array has only the empty subset.

Constraints

  • 0 <= len(nums) <= 10

Function contractsubsetsWithDupArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…