Stage 1 · Code
Backtracking
Permutations
All permutations with and without duplicates.
Unique Elements
Backtrack by swapping: for each position, try all remaining elements by swapping. Restore after recursion.
With Duplicates
Sort array first. Skip element if it's same as previous AND previous hasn't been used in current position (prevents duplicate permutations).
Next Permutation
Find lexicographically next permutation in-place. Algorithm: 1) Find longest non-increasing suffix. 2) Find pivot (element before suffix). 3) Find rightmost successor to pivot in suffix. 4) Swap pivot and successor. 5) Reverse suffix.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.