Given an array of distinct integers, return the count of all possible orderings.
Example
Input: 1 2 3
Output: 6
Approach
At each step, pick any one of the still-unused numbers next, recurse on the rest, and count a complete permutation once every number has been placed. This branches into exactly n! leaves.
Input format
Line 1: the array, space-separated
Print the total number of permutations.
Not solved yet
Ctrl+Enter
Editor
nums = list(map(int, input().split()))
result = []
# TODO: backtrack(path, remaining) — base case: remaining is emptydefbt(path, remaining):
ifnot remaining:
result.append(list(path))
return
Input (stdin)
Output
Run your code to see output here.
Isolated sandbox · not executed on your devicePowered by Judge0 CE (free, self-hosted). Runs in an isolated sandbox — not on your device.
Editor
nums = list(map(int, input().split()))
result = []
# TODO: backtrack(path, remaining) — base case: remaining is emptydefbt(path, remaining):
ifnot remaining:
result.append(list(path))
return
Input (stdin)
Output
Run your code to see output here.
Isolated sandbox · not executed on your devicePowered by Judge0 CE (free, self-hosted). Runs in an isolated sandbox — not on your device.