Permutations

medium

Each position picks one of the remaining values by swapping it forward. Undoing the swap restores the array exactly, so one array serves the entire search instead of n! copies.

Worst O(n × n!)Space O(n)
Loading the permutations engine…

Where to go next