Math Fundamentals18 sections · 814 units
Open in Course

Problem - Permutations

(LeetCode 46)

You are given an array of distinct integers. Your task: return all possible permutations of the array.

Example: [1,2,3] has 6 permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1].

This is a classic backtracking problem. You build permutations step by step, trying each element in each position.

Try it yourself first.