Dynamic Programming Python practice problems
State design, recurrences, memoization, tabulation, optimization, and overlapping subproblems.
Core concepts
Problem-solving patterns
- dynamic programming · Fibonacci
- house robber · DP
- coin change · bottom-up DP
- knapsack · space optimization
- LIS · binary search
What this topic builds
Learn the idea once, use it across the exercises, and explain why your approach works.
All 22 problems in this topic
Work from top to bottom to build the concept gradually.
- #327Count ways to climb stairs: Five stairsBeginnerPremium
Count different one-step and two-step sequences that reach stair five.
- #328Count ways to climb stairs: Zero stairsBeginnerPremium
There is one way to remain at the starting point: take no steps.
- #329Maximize nonadjacent house loot: Alternating opportunityIntermediatePremium
Find the maximum value without choosing adjacent houses.
- #330Maximize nonadjacent house loot: Two housesIntermediatePremium
Choose the larger value when the only two houses are adjacent.
- #331Find minimum coins: Reachable amountIntermediatePremium
Find the fewest coins needed to make eleven.
- #332Find minimum coins: Impossible amountIntermediatePremium
Return -1 when no combination can form the requested amount.
- #333Solve 0/1 knapsack: Choose best packageIntermediatePremium
Maximize value under a small carrying capacity.
- #334Solve 0/1 knapsack: No item fitsAdvancedPremium
Return zero when every item is heavier than the capacity.
- #335Find longest increasing subsequence length: Mixed sequenceAdvancedPremium
Find the LIS length in a common interview example.
- #336Find longest increasing subsequence length: Strictly decreasingAdvancedPremium
Only one value can belong to a strictly increasing subsequence.
- #337Find longest common subsequence length: Shared subsequenceAdvancedPremium
Find the LCS length for two strings with characters in common order.
- #338Find longest common subsequence length: No common charactersAdvancedPremium
Return zero when the strings share no character.
- #339Calculate edit distance: Classic conversionAdvancedPremium
Find the minimum edits needed to convert kitten to sitting.
- #340Calculate edit distance: Empty targetAdvancedPremium
Deleting every source character is optimal when the target is empty.
- #341Partition values into equal sums: Equal partition existsInterview-LevelPremium
Determine that the values can be split into two equal-sum groups.
- #342Partition values into equal sums: Equal partition impossibleInterview-LevelPremium
Return False when no subset reaches half of the total.
- #343Segment a string into dictionary words: Segmentable textInterview-LevelPremium
Check whether the complete string can be split into dictionary entries.
- #344Segment a string into dictionary words: Near match failsInterview-LevelPremium
Reject a string whose final characters cannot be covered by the dictionary.
- #345Count numeric message decodings: Several decodingsInterview-LevelPremium
Count all A-to-Z interpretations of a digit string.
- #346Count numeric message decodings: Leading zeroInterview-LevelPremium
A message beginning with zero has no valid decoding.
- #347Count unique paths with obstacles: One central obstacleInterview-LevelPremium
Count right-and-down routes that avoid a blocked cell.
- #348Count unique paths with obstacles: Start blockedInterview-LevelPremium
Return zero when the starting cell is blocked.