Distinct subsets with duplicates
Return all distinct subsets of an integer list as sorted lists, with the collection in lexicographic order.
values = [1, 2, 2]
start = 1
for i in range(start, len(values)):
print(i, i > start and values[i] == values[i-1])Reason about the state
Sort a copy and skip equal values only when they compete for the same recursion depth. Deeper equal values remain available to represent multiplicity. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Return all distinct subsets of an integer list as sorted lists, with the collection in lexicographic order.
The explanation opens here once every check passes.