TL;DR
- Recursion is a shape-matching tool: when the data is recursive, the solution often is too.
- Backtracking matters when I need to explore many valid combinations with pruning.
- I keep state, base cases, and rollback behavior explicit.
Context
Recursive patterns are useful for nested comments, menu trees, folder explorers, rule builders, and schema-driven UIs. Even when I do not ship recursive code directly, practicing it sharpens my decomposition skills.
The Approach
Practice these 10 medium-level questions:
- Flatten Nested Array — recursive traversal baseline.
- Generate All Subsets — classic inclusion/exclusion tree.
- Generate Unique Permutations — backtracking with duplicate control.
- Combination Sum — reuse candidates while pruning branches.
- Restore IP Addresses — constrained partitioning with validation.
- Word Search in Grid — DFS with visited-state rollback.
- Build File Paths From Tree — recursive path accumulation.
- Redact Nested JSON Keys — recursive object transform.
- Palindrome Partitioning — branch on valid prefix decisions.
- N-Queens — board constraint tracking and backtracking discipline.
Try it in the browser
Browser Practice
Recursion practice: flatten nested array
Implement solve(value) and return a flat array of all primitive values in order.
Sample Tests
2 checks
Function name:
solveBest for JavaScript / TypeScript / JSON practice snippets.Monospace editorRuns in browser sandbox
Trade-offs
- Recursion is expressive, but deep input can hit stack limits.
- Backtracking can explode combinatorially, so pruning strategy matters as much as correctness.
References
- Related: Coding Practice: Trees
- Related: Coding Practice: JSON & Object Transformations