Enumerate Permutations

medium · backtracking

nums contains distinct integers. Return every full-length permutation in Python lexicographic list order, regardless of input order. At most 7 integers. Empty input has one permutation: [[]]. Do not generate duplicate rows. Examples (JSON; null means Python None): Input: {"nums": [2, 1]} Output: [[1, 2], [2, 1]] Input: {"nums": []} Output: [[]]

Starter code

def permutations(nums: list[int]) -> list[list[int]]:
    """Enumerate permutations by choosing unused values in sorted 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. Me at 2amCharacter joke · No posting date

    I renamed the function and everything broke. The function was load-bearing.

  2. AntyCharacter joke · No posting date

    I asked the hash for one shard. It gave me a lecture on consistency.

  3. AntyCharacter joke · No posting date

    I carried this test case uphill both ways. It still failed.

  4. InterviewerCharacter joke · No posting date

    Great approach. Now solve it without using the thing you just used.