FrontendX
Permutations III
medium
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Permutations
III
Given a number n (1-9), generate all permutations of numbers 1 to n in lexicographic order.
Examples
Example 1
Input:
1
Output:
[[1]]
Example 2
Input:
2
Output:
[[1,2],[2,1]]
Hints
Hint 1
Use backtracking to generate all permutations.
Hint 2
For lexicographic order, start from 1 and increment sequentially.
Hint 3
Track used numbers to avoid repetition.
Related Problems
24-game
additive-number
all-paths-from-source-to-target
Permutations III
Given a number n (1-9), generate all permutations of numbers 1 to n in lexicographic order.