Standard Bar Recursion · Subsequences Pattern O(n * 2^n) — copying each subset costs up to O(n) · O(n) recursion depth beyond the output
A radio scheduler builds every possible segment lineup from a track list that contains repeated titles. Two lineups with the same multiset of titles count as the same segment, so the scheduler sorts the list first and, when several identical titles sit side by side, refuses to start a new branch on the second copy of a title at the same depth. Every node of the resulting tree — not just the leaves — is a valid distinct lineup.
Input: An array nums of n integers, possibly with duplicates.
Output: All distinct subsets; the verifier compares them as a set of sorted tuples.
1 <= n <= 10-10 <= nums[i] <= 10Input: {"nums":[1,2,2]}
Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
Sorted lexicographically: the second 2 never starts a fresh branch at the same depth, killing duplicate subsets.
Input: {"nums":[0]}
Output: [[],[0]]
Distinct elements behave like the plain power set.