Dashboard
LC #46

Permutations

Pattern · ?AmazonGoogleMetaLinkedInMicrosoft

Problem

Return all possible permutations of an array of distinct integers.

Constraints

  • 1 ≤ n ≤ 6
  • -10 ≤ nums[i] ≤ 10
  • All values are unique

Example

Input
nums = [1, 2, 3]
Output
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Why
3! = 6 permutations. Return in any order

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗