Skip to interview prep
Apexed

50. Permutations

MediumRecursion & backtracking

Return every permutation of the distinct integers nums, in lexicographic order.

Example 1

Input: nums = [1, 2, 3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]

Constraints

  • 1 ≤ nums.length ≤ 7

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 3 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Permutations — coding interview practice — Apexed