Problem Archetypes
A handful of recurring problem families cover most interview DP. Each family is defined by a recurrence you can state and defend — recognize the family and the state, transition, and complexity follow almost mechanically.
part ofData structures & algorithmsoverview, primer and where to startread it →on this pageshowhide
explore
- 1D Sequence DP4 questions
- Knapsack Family8 questions
- 0/1 Knapsack & Subset Sum4 questions
- Unbounded Knapsack & Coin Change4 questions
- String DP9 questions
- LCS & Edit Distance4 questions
- Palindrome DP5 questions
- Grid-Path DP4 questions
- Advanced DP Patterns12 questions
- Interval DP4 questions
- Bitmask DP4 questions
- DP on Trees4 questions
- AI & Data Scientistrole
- AI Engineerrole
- AI Red Teamingrole
- Android Developerrole
- Backend Developerrole
- Blockchain Developerrole
- Computer Scienceskill
- Cyber Security Expertrole
- Data Analystrole
- Data Engineerrole
- Data Structures & Algorithmsskill
- DevOps / SRE Engineerrole
- DevSecOps Engineerrole
- Forward Deployed Engineerrole
- Frontend Developerrole
- Full Stack Developerrole
- Game Developerrole
- Java Backend Developerrole
- Java SDETrole
- Kotlin Backend Developerrole
- MLOps Engineerrole
- Machine Learning Engineerrole
- Network Engineerrole
- PostgreSQL DBArole
- QA Engineerrole
- Software Architectrole
- iOS Developerrole
questions
page 2 of 2Aligning two 100k-character documents needs 10^10 table cells. What do you change before writing the loop?
basics
~20 sAttack the cell count, not the memory: quadratic time bites before space does. Trim the shared prefix and suffix, compare coarser units such as fingerprinted lines, and if only k edits matter, fill just the band where |i-j| <= k, which is O(n*k).
When does an interval DP table beat O(1)-space center expansion for palindromes in long gene reads?
basics
~20 sOnly when something else will query the table. Both methods cost O(n^2) time for one longest symmetric run, but the table also costs O(n^2) memory. It pays off when an enclosing computation asks "is i..j symmetric?" many times, or when you need counts over all intervals.
When does the O(nW) 0/1 knapsack table lose to exponential subset search, and how do you decide?
basics
~20 sThe table loses when the capacity limit is enormous and the item count is not: 30 items and a billion-unit limit cost tens of billions of updates and gigabytes, while halved subset enumeration takes about a million operations.
After the O(n log n) longest-increasing-subsequence scan, what does the tails array actually contain?
basics
~20 sThe tails array holds at position k the smallest value that can end an increasing subsequence of length k+1. Its final length is the answer, but its contents are usually not a real subsequence of the input.
Your exact subset-DP route planner tops out near 20 stops, but dispatch now needs 35 — how do you decide what replaces it?
basics
~20 sSubset DP's ceiling is exponential memory, so no tuning reaches 35 stops — the method must change. The real decision is what the last few percent of route quality is worth against a planner the team can operate and maintain.
Your planner parenthesizes a fixed chain of joins with interval DP — when do you abandon the exact search?
basics
~20 sAbandon it when planning cost stops buying execution savings: when quadratic memory or cubic time breaks the per-request budget, or when the size estimates feeding the cost function are so uncertain that the exact optimum is optimal only for a fiction.
When is a rerooting tree DP worth its complexity over simply running one traversal per candidate root?
basics
~20 sRerooting answers every node in two linear passes instead of one traversal per node, turning quadratic work into linear. Take it when the measured input size and recompute frequency actually miss the latency budget; below a few thousand nodes the simpler per-root loop usually wins and is far easier to keep correct.
showing 31–37 of 37