The Permutations problem asks you to return all possible permutations of a given array of distinct integers. This Permutations coding problem is the canonical backtracking problem — every backtracking algorithm builds on this fundamental template. The array and backtracking interview pattern is the most essential skill demonstrated here.
J.P. Morgan, Apple, Goldman Sachs, Microsoft, Meta, Amazon, Google, Bloomberg, and Adobe ask this because it's the foundational backtracking problem. Every candidate is expected to implement this cleanly. It validates understanding of state management, recursive exploration, and result collection in backtracking.
Backtracking with used array. Maintain a used boolean array and current list. At each recursive call: if len(current) == n, add a copy to results. For each index i from 0..n-1: if not used[i], mark used[i]=True, append arr[i], recurse, then unmark and remove (backtrack).
nums=[1,2,3]. Start backtrack from empty path.
Permutations is the backtracking archetype. Master the template: mark → explore → unmark. This pattern appears in: permutations, subsets, combinations, word search, N-queens, and dozens more. The copy-on-result is critical: always add a copy of current, not current itself. Practice implementing Permutations I, then II (with duplicates), then III (alternating), to build complete backtracking mastery.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Combination Sum | Medium | Solve | |
| Combination Sum II | Medium | Solve | |
| Combination Sum III | Medium | Solve | |
| Construct the Lexicographically Largest Valid Sequence | Medium | Solve | |
| Permutations III | Medium | Solve |