InterviewStack.io LogoInterviewStack.io

Recursion and Dynamic Programming Questions

Covers recursive problem solving and dynamic programming as core algorithmic techniques. For recursion, understand how functions call themselves, base and recursive cases, the call stack, common patterns such as tree and graph traversals, backtracking, permutations, and detecting and avoiding infinite recursion. For dynamic programming, understand when to apply optimization via memoization and bottom up approaches, recognize optimal substructure and overlapping subproblems, convert naive recursive solutions into memoized or tabulated solutions, and analyze time and space complexity tradeoffs. Familiarity with classic examples such as Fibonacci, longest common subsequence, knapsack, coin change, and path counting is expected. At more senior levels, be able to discuss performance considerations, space optimization, and how DP principles can map onto real systems such as caching strategies, state management, and optimization of workflows or database query plans.

EasyTechnical
68 practiced
When using recursion to traverse a graph (DFS), it's important to avoid infinite recursion due to cycles. Implement a recursive DFS in Python that detects and avoids cycles; given a directed graph represented as adjacency list, return True if there's a path between two nodes. Describe how a visited set or recursion stack differs and when to use each.
HardTechnical
73 practiced
Given a grid where each cell has a non-negative cost that may change over time, design an algorithm to compute the minimum-cost path from top-left to bottom-right if costs are updated in small batches between queries. Discuss DP approaches plus efficient incremental update techniques (e.g., dynamic shortest path, Dijkstra variants) and when to recompute from scratch versus incremental updates.
MediumTechnical
86 practiced
You are given a top-down recursive DP pseudocode (e.g., for LCS or knapsack). Explain how to convert it into a bottom-up tabulation approach. Walk through the conversion using the LCS recursive formulation as the example and discuss ordering of loops and initialization of base cases.
MediumTechnical
96 practiced
Tree DP: Implement the 'House Robber III' problem where thieves cannot rob two directly-linked houses (a binary tree). Return the maximum amount that can be robbed. Use recursion with memoization and explain your state definition and transitions in terms of including/excluding root.
HardTechnical
95 practiced
Solve the Traveling Salesman Problem for n ≤ 20 using bitmask dynamic programming: implement a solution in Python that returns the minimum tour length given a full distance matrix. Explain the O(n^2 * 2^n) complexity and memory usage, and discuss pruning or heuristics you might use to handle n slightly larger than 20 in practice.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.