Problem. Given nums that may contain duplicates, return all distinct subsets. Two subsets are the same
if they contain the same values with the same multiplicities, whatever the order.
nums = [1, 2, 2] → [], [1], [2], [1, 2], [2, 2], [1, 2, 2] (6, not 2³ = 8)
nums = [0] → [], [0]
Lesson 8.3's method would produce [2] twice (from either copy) and [1, 2] twice. The task is to never generate the
duplicates in the first place.
ML context. Pools with repeats are common: a list of augmentations where some are listed twice to weight them, an ensemble pool with several identical model configs, a bag of tokens. "All distinct combinations" from such a pool must not waste time (or GPU runs) on repeats. And often you only need how many distinct combinations there are, which has a closed form (Change B).