Field note / fundamentals

publishedupdated 2026-05-04#algorithms#recursion#backtracking#combinatorics#frontend

Coding Practice: Recursion and Backtracking

Ten medium-level recursion questions covering nested data, combinatorial search, branching, and backtracking control.

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:

  1. Flatten Nested Array — recursive traversal baseline.
  2. Generate All Subsets — classic inclusion/exclusion tree.
  3. Generate Unique Permutations — backtracking with duplicate control.
  4. Combination Sum — reuse candidates while pruning branches.
  5. Restore IP Addresses — constrained partitioning with validation.
  6. Word Search in Grid — DFS with visited-state rollback.
  7. Build File Paths From Tree — recursive path accumulation.
  8. Redact Nested JSON Keys — recursive object transform.
  9. Palindrome Partitioning — branch on valid prefix decisions.
  10. 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: solve
Best 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