Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
A permutation is an arrangement of all elements where order matters. For n distinct elements, there are n! (n factorial) possible permutations.
Unlike subsets where we choose to include/exclude elements, in permutations we must use ALL elements exactly once, just in different orders. At each position in the permutation, we can place any element that hasn't been used yet.
The backtracking approach: at each step, try placing each unused element, recurse, then backtrack by unmarking the element as used.
nums = [1,2,3][[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]nums = [0,1][[0,1],[1,0]]nums = [1][[1]]1 <= nums.length <= 6-10 <= nums[i] <= 10All the integers of nums are uniqueClick "Run" to execute your code against test cases
Socratic guidance - I'll ask questions, not give answers