Chapter 10: Problem Recognition Drills

You have learned the patterns, derived recurrences, and even optimized beyond O(n²). But there is one skill that separates people who know DP from people who can use DP under pressure: recognizing which pattern fits before writing a single line of code.

This skill is not innate — it is built through deliberate practice. Read a problem statement, classify the pattern, define the subproblem, and check your answer. The drills below are designed for exactly that. Do not rush. Wrong guesses are learning opportunities, not failures.

Pattern recognition is the meta-skill of dynamic programming. Once you can glance at a problem and think “this is interval DP on a range,” the five-step framework from Chapter 2 does the rest. These drills train that glance.

Quick Reference: All Patterns

Keep this table in mind as you work through the drills. The “key signal” column is what you should look for in the problem statement.

PatternKey SignalSubproblem ShapeExample
1D DPLinear sequence, decision at each indexdp[i]House Robber
2D DPTwo sequences, or griddp[i][j]LCS, Knapsack
IntervalSplitting/merging rangesdp[i][j] for range [i,j]Matrix Chain
TreeDP on tree structuredp[node]House Robber III
BitmaskSubset tracking, n ≤ 20dp[mask]TSP
DigitCount numbers with digit propertiesdp[pos][state][tight]Count Special

Drill Set 1: Pattern Classification

Read each problem statement and select the DP pattern it belongs to. After answering, read the explanation — even for problems you got right — to reinforce the signals that led to the correct classification.

Pattern Recognition0/0 correct

Given an array, find the maximum sum of non-adjacent elements.

Drill Set 2: Subproblem Definition

Recognizing the pattern is step one. Step two is defining what your DP table represents. A vague definition like “dp[i] is the answer for i” is not enough — be precise about what is included, excluded, and optimized.

Rod Cutting: What does dp[i] represent?

Palindrome Partitioning: What does dp[i] represent?

Egg Drop: What does dp[k][n] represent?

Longest Palindromic Subsequence: What does dp[i][j] represent?

Word Break: What does dp[i] represent?

If you cannot write a one-sentence definition of dp[i] or dp[i][j], you are not ready to write the recurrence. Pause, re-read the problem, and ask: “What is the smallest subproblem whose answer I need to know?”

Spaced Repetition Review

The problems below combine everything from Drill Set 1 with ten additional problems for variety. The spaced repetition system tracks which problems you find easy and surfaces the ones you need to review. Come back to this section over the next few days — spaced practice is how recognition becomes automatic.

Spaced Repetition Review

Problems you miss come back sooner. Correct answers space out over time.

20 due for review

0 scheduled for later

Closing Remarks

Congratulations — you have worked through the full arc of dynamic programming: from mindset and the five-step framework, through every major pattern, to advanced optimizations and now deliberate recognition practice. That is a serious body of knowledge.

But mastery is not a destination. Keep practicing with the 5-step framework every time you encounter a new problem:

  1. Define the subproblem precisely.
  2. Identify the last decision.
  3. Write the recurrence.
  4. Establish base cases.
  5. Determine fill order.

For more problems, explore the Dynamic Programming tag on LeetCode. Start with medium problems in patterns you know, then branch into unfamiliar territory and classify before you code.

The best competitive programmers and engineers do not memorize solutions — they recognize shapes. Every problem in this tutorial was an instance of a pattern you now know. The next problem you face will be too. Trust the process, keep drilling, and the glance will get faster every week.