PythonStudio
Interview Problems

Enumerate Subsets

easy · backtracking

nums contains distinct integers. Return all subsets. Each subset must be sorted ascending and the OUTER list must be in Python lexicographic list order (the empty list comes first, a prefix comes before extensions). Input order does not affect output. At most 10 integers. Return [[]] for empty input. Examples (JSON; null means Python None): Input: {"nums": [2, 1]} Output: [[], [1], [1, 2], [2]] Input: {"nums": []} Output: [[]]

Starter code

def subsets(nums: list[int]) -> list[list[int]]:
    """Enumerate subsets in deterministic lexicographic order."""
    pass
Loading editor…

Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.

Return to the Python compiler