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
- AlgorithmsCoding exercise
Binary Tree Equal
EASYImplement a function that returns whether two binary trees have identical structure and node values.
15 minPractice - AlgorithmsCoding exercise
Binary Tree Maximum Depth
EASYImplement a function that returns the maximum depth from root to leaf in a binary tree.
15 minPractice - AlgorithmsCoding exercise
Flip Binary Tree
EASYImplement a function that mirrors a binary tree by swapping the left and right children of every node.
15 minPractice - AlgorithmsCoding exercise
Staircase Climbing Combinations
EASYImplement a function that counts the distinct ways to climb to the top of a staircase taking one or two steps.
15 minPractice - AlgorithmsCoding exercise
0/1 Knapsack
MEDIUMMaximize 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 minPractice - JavaScriptCoding exercise
Arithmetic Expression Evaluator
MEDIUMTokenize and evaluate a math expression string with operator precedence, parentheses, and unary minus.
35 minAmazon · Google · MicrosoftPractice - AlgorithmsCoding exercise
Binary Search Tree Kth Smallest Element
MEDIUMImplement a function that returns the kth smallest value in a binary search tree.
25 minPractice - AlgorithmsCoding exercise
Binary Search Tree Lowest Common Ancestor
MEDIUMImplement a function that finds the lowest common ancestor of two nodes in a binary search tree.
25 minPractice - AlgorithmsCoding exercise
Binary Tree Rebuilding from Preorder and Inorder Traversals
MEDIUMImplement a function that reconstructs a binary tree given its preorder and inorder traversal sequences.
25 minPractice - AlgorithmsCoding exercise
Binary Tree Subtree
MEDIUMImplement a function that determines whether one binary tree appears as a subtree of another.
25 minPractice - JavaScriptCoding exercise
Camel Case Keys
MEDIUMImplement a function that returns a new object with every key converted to camelCase, recursing into nested objects.
25 minAirbnb · GooglePractice - AlgorithmsCoding exercise
Combinations for Target Sum
MEDIUMImplement a function that returns every unique combination of reusable candidates that sums to a target.
25 minPractice - JavaScriptCoding exercise
Compact II
MEDIUMImplement a function that returns a deep copy of an object with all falsy values stripped from nested structures.
25 minPremium questionPractice - AlgorithmsCoding exercise
Count Islands in a Grid
MEDIUMImplement a function that counts the number of distinct islands of connected cells in a 2D binary grid.
25 minAdobePractice - JavaScriptCoding exercise
Deep Clone
MEDIUMImplement a function that recursively clones a JSON-serializable value without sharing references.
25 minAdobe · Amazon · ByteDance +4Practice - JavaScriptCoding exercise
Deep Freeze
MEDIUMRecursively freeze an object and every nested object and array, making the whole structure deeply immutable.
25 minPremium questionPractice - JavaScriptCoding exercise
Deep Map
MEDIUMImplement a function that walks an arbitrarily nested structure and applies a transform to every leaf value.
25 minGooglePractice - JavaScriptCoding exercise
Deep Merge
MEDIUMImplement a function that recursively merges two objects, combining nested properties rather than overwriting them.
25 minPractice - JavaScriptCoding exercise
Deep Omit
MEDIUMImplement a function that returns a copy of a value with the given keys stripped from every nested object.
25 minGooglePractice - JavaScriptCoding exercise
Dependency Injection Container
MEDIUMBuild a DI container that resolves a service dependency graph, caches singletons, and detects circular dependencies.
25 minGoogle · Microsoft · UberPractice - AlgorithmsCoding exercise
Depth-First Search
MEDIUMImplement depth-first traversal of a directed graph, exploring each branch fully before backtracking.
25 minPractice - AlgorithmsCoding exercise
Distinct Paths in Grid
MEDIUMImplement 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 minPractice - AlgorithmsCoding exercise
Edit Distance
MEDIUMCompute the minimum number of insertions, deletions, and replacements to turn one string into another — the Levenshtein distance via a 2D dynamic-programming table.
25 minPractice - AlgorithmsCoding exercise
Fast Power
MEDIUMRaise a base to an integer exponent in logarithmic time using exponentiation by squaring, handling negative exponents.
25 minPractice - UI / FrameworksUI challenge4 variants
File Explorer
MEDIUMBuild a file explorer that renders a nested folder hierarchy and lets you expand and collapse directories.
25 minAdobe · Amazon · Atlassian +7Practice - JavaScriptCoding exercise
Flatten
MEDIUMImplement a function that recursively flattens a nested array into a single-level array.
25 minAirbnb · Amazon · Apple +10Practice - AlgorithmsCoding exercise
GCD / LCM
MEDIUMCompute the greatest common divisor with Euclid's algorithm and the least common multiple, for two numbers or a whole list.
25 minPremium questionPractice - AlgorithmsCoding exercise
Generate Parentheses
MEDIUMGenerate 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 minPractice - JavaScriptCoding exercise
HTML Serializer
MEDIUMImplement a function that serializes a tree-shaped object into a pretty-printed HTML string with indentation.
25 minTikTokPractice - JavaScriptCoding exercise
Identical DOM Trees
MEDIUMImplement a function that recursively compares two DOM trees and returns whether they are structurally equal.
25 minIntuitPractice - JavaScriptCoding exercise
JSON.stringify
MEDIUMImplement a function that converts a JavaScript value into its JSON string representation.
25 minAmazon · Google · Meta +4Practice - AlgorithmsCoding exercise
Merge Sort
MEDIUMImplement merge sort recursively by splitting the array and merging the sorted halves back together.
25 minPractice - UI / FrameworksUI challenge4 variants
Nested Comments
MEDIUMBuild a threaded comments tree where each comment can be replied to and collapsed recursively.
25 minReddit · ServicenowPractice - AlgorithmsCoding exercise
Palindrome Partitioning
MEDIUMSplit 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 minPractice - AlgorithmsCoding exercise
Permutations & Subsets
MEDIUMGenerate every permutation and every subset of an array with the same backtracking template — choose, recurse, and undo.
25 minPractice - AlgorithmsCoding exercise
Phone Letter Combinations
MEDIUMList every letter string a phone number could spell, mapping each digit to its keypad letters and backtracking through the choices.
25 minPractice - AlgorithmsCoding exercise
Quick Sort
MEDIUMImplement quick sort recursively, partitioning around a pivot and sorting each side independently.
25 minPractice - JavaScriptCoding exercise
Squash Object
MEDIUMImplement a function that flattens a nested object into a single-level object using dot-delimited keys.
25 minPractice - JavaScriptCoding exercise
Unsquash Object
MEDIUMImplement a function that rebuilds a nested object from a flat map of dot-delimited keys.
25 minPractice - AlgorithmsCoding exercise
Binary Search Tree
HARDBuild a binary search tree with insert, search, and delete operations preserving the BST invariant.
40 minPremium questionPractice - AlgorithmsCoding exercise
Binary Tree Maximum Total Path
HARDImplement a function that returns the maximum sum of node values along any path in a binary tree.
40 minPremium questionPractice - JavaScriptCoding exercise
Deep Clone II
HARDImplement a deep clone that copies nested values and correctly handles circular references using a visited map.
40 minByteDance · TikTokPractice - JavaScriptCoding exercise
Deep Equal
HARDImplement a function that determines whether two values are structurally equal across nested objects and arrays.
40 minGooglePractice - JavaScriptCoding exercise
JSON.parse
HARDImplement JSON.parse — a recursive-descent parser that turns a JSON string into the corresponding JavaScript value.
40 minAmazon · Google · Microsoft +1Practice - JavaScriptCoding exercise
JSON.stringify II
HARDImplement JSON.stringify with full spec support including replacer, indentation, and circular reference detection.
40 minAmazon · Google · Netflix +1Practice - UI / FrameworksUI challenge4 variants
Lazy Tree View
HARDBuild a collapsible tree that lazily loads a node's children the first time it is expanded.
40 minPremium questionPractice - UI / FrameworksUI challenge4 variants
Minesweeper
HARDBuild Minesweeper with flood-fill reveal, flagging, and win/lose detection.
40 minPremium questionPractice - AlgorithmsCoding exercise
N-Queens
HARDPlace 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 minPremium questionPractice - UI / FrameworksUI challenge4 variants
Nested Checkboxes
HARDBuild a nested checkbox tree where parent state reflects its children and toggling a parent cascades down.
40 minGoogle · MetaPractice - JavaScriptCoding exercise
Schema Validator III
HARDExtend a tiny schema validator to handle nested object and array shapes plus optional fields.
40 minPremium questionPractice - JavaScriptCoding exercise
structuredClone
HARDImplement structuredClone — deep-clone a value including Map, Set, Date, RegExp, typed arrays, and circular references.
40 minPremium questionPractice - AlgorithmsCoding exercise
Sudoku Solver
HARDFill 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 minPremium questionPractice - JavaScriptCoding exercise
Superjson II
HARDBuild serialize and deserialize that preserve referential identity — shared references and circular structures round-trip intact.
40 minPremium questionAnthropic · OpenAIPractice - AlgorithmsCoding exercise
Wildcard Matching
HARDDecide whether a string matches a pattern containing `?` (any single character) and `*` (any sequence) — a two-dimensional dynamic-programming match over string and pattern.
40 minPremium questionPractice