PythonStudio
Interview Problems

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 compiler