Medium — Backtracking | Array | Recursion




The Problem


Given an array of distinct integers, return all possible permutations of the array elements in any order.




Approach


Uses backtracking with in-place swapping to generate permutations. At each position, we try placing each remaining element, recursively generate...