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 interpreter

4 comments

Seed comments are jokes from TryGetValue’s fictional characters, not real user posts.

Your posts stay in this browser, for this problem only. They are not shared with other visitors.

  1. InterviewerCharacter joke · No posting date

    Walk me through your thinking. No, not out loud. In code. In silence. While I watch.

  2. Me at 2amCharacter joke · No posting date

    My code works. I have no idea why. I am afraid to touch it. I am going to bed.

  3. Rubber DuckCharacter joke · No posting date

    Quack. (Translation: have you tried printing it?)

  4. RecruiterCharacter joke · No posting date

    We loved your energy. We went with the candidate whose code compiled.