Recursion interview questions
Practice 54 questions on recursion. Each runs in a real in-browser editor with Jest tests and a worked, diagram-backed solution.
54 questions
- EASY
Binary Tree Equal
Implement a function that returns whether two binary trees have identical structure and node values.
15 minAlgorithms - EASY
Binary Tree Maximum Depth
Implement a function that returns the maximum depth from root to leaf in a binary tree.
15 minAlgorithms - EASY
Flip Binary Tree
Implement a function that mirrors a binary tree by swapping the left and right children of every node.
15 minAlgorithms - EASY
Staircase Climbing Combinations
Implement a function that counts the distinct ways to climb to the top of a staircase taking one or two steps.
15 minAlgorithms - MEDIUM
0/1 Knapsack
PREMIUMMaximize the value packed into a weight-limited knapsack when each item can be taken at most once — the classic 0/1 dynamic-programming table.
25 minAlgorithms - MEDIUM
Arithmetic Expression Evaluator
Tokenize and evaluate a math expression string with operator precedence, parentheses, and unary minus.
35 minJavaScriptGoogle · Amazon · Microsoft - MEDIUM
Binary Search Tree Kth Smallest Element
Implement a function that returns the kth smallest value in a binary search tree.
25 minAlgorithms - MEDIUM
Binary Search Tree Lowest Common Ancestor
Implement a function that finds the lowest common ancestor of two nodes in a binary search tree.
25 minAlgorithms - MEDIUM
Binary Tree Rebuilding from Preorder and Inorder Traversals
Implement a function that reconstructs a binary tree given its preorder and inorder traversal sequences.
25 minAlgorithms - MEDIUM
Binary Tree Subtree
Implement a function that determines whether one binary tree appears as a subtree of another.
25 minAlgorithms - MEDIUM
Camel Case Keys
Implement a function that returns a new object with every key converted to camelCase, recursing into nested objects.
25 minJavaScript - MEDIUM
Combinations for Target Sum
Implement a function that returns every unique combination of reusable candidates that sums to a target.
25 minAlgorithms - MEDIUM
Compact II
Implement a function that returns a deep copy of an object with all falsy values stripped from nested structures.
25 minJavaScript - MEDIUM
Count Islands in a Grid
Implement a function that counts the number of distinct islands of connected cells in a 2D binary grid.
25 minAlgorithms - MEDIUM
Deep Clone
PREMIUMImplement a function that recursively clones a JSON-serializable value without sharing references.
25 minJavaScript - MEDIUM
Deep Freeze
Recursively freeze an object and every nested object and array, making the whole structure deeply immutable.
25 minJavaScript - MEDIUM
Deep Map
PREMIUMImplement a function that walks an arbitrarily nested structure and applies a transform to every leaf value.
25 minJavaScript - MEDIUM
Deep Merge
PREMIUMImplement a function that recursively merges two objects, combining nested properties rather than overwriting them.
25 minJavaScript - MEDIUM
Deep Omit
PREMIUMImplement a function that returns a copy of a value with the given keys stripped from every nested object.
25 minJavaScript - MEDIUM
Dependency Injection Container
Build a DI container that resolves a service dependency graph, caches singletons, and detects circular dependencies.
25 minJavaScriptGoogle · Microsoft · Uber - MEDIUM
Depth-First Search
Implement depth-first traversal of a directed graph, exploring each branch fully before backtracking.
25 minAlgorithms - MEDIUM
Distinct Paths in Grid
Implement a function that counts the number of unique paths a robot can take from the top-left to bottom-right of an m by n grid.
25 minAlgorithms - MEDIUM
Edit Distance
PREMIUMCompute the minimum number of insertions, deletions, and replacements to turn one string into another — the Levenshtein distance via a 2D dynamic-programming table.
25 minAlgorithms - MEDIUM
Fast Power
Raise a base to an integer exponent in logarithmic time using exponentiation by squaring, handling negative exponents.
25 minAlgorithms - MEDIUM
File Explorer
Build a file explorer that renders a nested folder hierarchy and lets you expand and collapse directories.
25 minUI / FrameworksAngularReactHTML / CSS / JSVue - MEDIUM
Flatten
Implement a function that recursively flattens a nested array into a single-level array.
25 minJavaScript - MEDIUM
GCD / LCM
Compute the greatest common divisor with Euclid's algorithm and the least common multiple, for two numbers or a whole list.
25 minAlgorithms - MEDIUM
Generate Parentheses
Generate every well-formed combination of n pairs of parentheses by backtracking — add an open bracket while any remain, and a close bracket only while it stays balanced.
25 minAlgorithms - MEDIUM
HTML Serializer
Implement a function that serializes a tree-shaped object into a pretty-printed HTML string with indentation.
25 minJavaScript - MEDIUM
Identical DOM Trees
Implement a function that recursively compares two DOM trees and returns whether they are structurally equal.
25 minJavaScript - MEDIUM
JSON.stringify
PREMIUMImplement a function that converts a JavaScript value into its JSON string representation.
25 minJavaScript - MEDIUM
Merge Sort
Implement merge sort recursively by splitting the array and merging the sorted halves back together.
25 minAlgorithms - MEDIUM
Nested Comments
PREMIUMBuild a threaded comments tree where each comment can be replied to and collapsed recursively.
25 minUI / FrameworksAngularReactHTML / CSS / JSVue - MEDIUM
Palindrome Partitioning
Split a string every possible way so that each piece is a palindrome — backtrack over cut positions, extending a piece only while it reads the same both ways.
25 minAlgorithms - MEDIUM
Permutations & Subsets
PREMIUMGenerate every permutation and every subset of an array with the same backtracking template — choose, recurse, and undo.
25 minAlgorithms - MEDIUM
Phone Letter Combinations
List every letter string a phone number could spell, mapping each digit to its keypad letters and backtracking through the choices.
25 minAlgorithms - MEDIUM
Quick Sort
Implement quick sort recursively, partitioning around a pivot and sorting each side independently.
25 minAlgorithms - MEDIUM
Squash Object
Implement a function that flattens a nested object into a single-level object using dot-delimited keys.
25 minJavaScript - MEDIUM
Unsquash Object
Implement a function that rebuilds a nested object from a flat map of dot-delimited keys.
25 minJavaScript - HARD
Binary Search Tree
PREMIUMBuild a binary search tree with insert, search, and delete operations preserving the BST invariant.
40 minAlgorithms - HARD
Binary Tree Maximum Total Path
PREMIUMImplement a function that returns the maximum sum of node values along any path in a binary tree.
40 minAlgorithms - HARD
Deep Clone II
PREMIUMImplement a deep clone that copies nested values and correctly handles circular references using a visited map.
40 minJavaScript - HARD
Deep Equal
PREMIUMImplement a function that determines whether two values are structurally equal across nested objects and arrays.
40 minJavaScript - HARD
JSON.parse
PREMIUMImplement JSON.parse — a recursive-descent parser that turns a JSON string into the corresponding JavaScript value.
40 minJavaScript - HARD
JSON.stringify II
PREMIUMImplement JSON.stringify with full spec support including replacer, indentation, and circular reference detection.
40 minJavaScript - HARD
Lazy Tree View
PREMIUMBuild a collapsible tree that lazily loads a node's children the first time it is expanded.
40 minUI / FrameworksAngularReactHTML / CSS / JSVue - HARD
Minesweeper
PREMIUMBuild Minesweeper with flood-fill reveal, flagging, and win/lose detection.
40 minUI / FrameworksAngularReactHTML / CSS / JSVue - HARD
N-Queens
PREMIUMPlace N queens on an N×N board so none attack another — a classic backtracking search that places one queen per row and prunes column and diagonal conflicts.
40 minAlgorithms - HARD
Nested Checkboxes
PREMIUMBuild a nested checkbox tree where parent state reflects its children and toggling a parent cascades down.
40 minUI / FrameworksAngularReactHTML / CSS / JSVue - HARD
Schema Validator III
PREMIUMExtend a tiny schema validator to handle nested object and array shapes plus optional fields.
40 minJavaScript - HARD
structuredClone
PREMIUMImplement structuredClone — deep-clone a value including Map, Set, Date, RegExp, typed arrays, and circular references.
40 minJavaScript - HARD
Sudoku Solver
PREMIUMFill a 9×9 Sudoku grid by backtracking — try each digit in the next empty cell, checking its row, column, and 3×3 box, and undo on a dead end.
40 minAlgorithms - HARD
Superjson II
PREMIUMBuild serialize and deserialize that preserve referential identity — shared references and circular structures round-trip intact.
40 minJavaScript - HARD
Wildcard Matching
PREMIUMDecide whether a string matches a pattern containing `?` (any single character) and `*` (any sequence) — a two-dimensional dynamic-programming match over string and pattern.
40 minAlgorithms