InterviewStack.io LogoInterviewStack.io

Recursion and Backtracking Questions

Master the mechanics of recursion including base cases recursive cases and call stack behavior. Understand and apply backtracking as a search pattern for combinatorial problems such as generating permutations combinations subsets solving N Queens and Sudoku and grid path finding. Learn state management techniques in recursive code including when to use immutable local state versus shared mutable state how to restore or undo changes when backtracking and how to avoid accidental state leakage. Practice pruning techniques constraint propagation and other optimizations to reduce the explored search space and avoid exponential explosion. Know how to convert recursive solutions to equivalent iterative or explicit stack based implementations and understand time and space complexity tradeoffs. Be able to recognize when recursion or backtracking is appropriate versus alternative techniques such as dynamic programming greedy algorithms or straightforward iteration and to implement common templates for building and undoing partial solutions.

MediumTechnical
43 practiced
Explain the difference between plain DFS and backtracking. Use examples to show when DFS is used for traversal (e.g., reachability) versus when backtracking is used for constructing and undoing partial solutions (e.g., permutations). Discuss how cycle handling and visited sets differ between the two patterns.
EasyTechnical
52 practiced
Implement a recursive method reverseString(s) in Java that returns the reversed string. Do not use loops or library reverse utilities. Explain your chosen base case and recursive case, handle null and empty inputs, and provide unit tests for edge cases (single char, empty, null). Discuss time and space complexity and recursion depth implications for very large strings.
HardTechnical
53 practiced
Implement a backtracking algorithm in Java to enumerate all Hamiltonian paths in a small undirected graph (n <= 15). Signature: List<List<Integer>> hamiltonianPaths(int n, List<List<Integer>> adj). Discuss pruning heuristics such as ordering by remaining degree, early exit on disconnected components, and using bitmask visited states for efficient checks.
HardTechnical
50 practiced
During a code review you find a candidate's recursive backtracking solution uses a mutable result list incorrectly and also lacks pruning, causing poor performance and incorrect outputs. Draft constructive feedback you would give, propose specific code changes, and outline a 4-week mentoring plan (exercises, readings, pair-programming) to help them master recursion/backtracking patterns.
HardTechnical
39 practiced
Prove or reason about the time complexity of generating all C(n,k) combinations using backtracking and discuss memory tradeoffs when storing results versus streaming them. Describe an implementation of a lazy iterator in your language of choice that enumerates combinations without holding all results in memory and explain amortized cost per yielded combination.

Unlock Full Question Bank

Get access to hundreds of Recursion and Backtracking interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.