Dynamic Programming Questions

Solving problems with overlapping subproblems and optimal substructure by memoization (top-down) and tabulation (bottom-up). Covers recognizing DP-amenable problems, defining state, transition and base cases, 1D and 2D sequence and grid formulations (knapsack and its variants, coin change, LIS, LCS, edit distance, sequence alignment, regular-expression and wildcard matching, counting-ways problems), interval DP (matrix chain, palindrome partitioning), space optimization with rolling arrays, solution reconstruction, longest paths in a DAG, game and expected-value DP, bitmask and tree DP, speeding up a DP (monotone queue, convex hull trick, divide-and-conquer optimization, bitsets, meet in the middle), and judging greedy versus DP. Ground covered elsewhere: probabilistic model inference, production caching and debugging practice, and general graph shortest-path algorithms.

MediumTechnical
90 practiced

Compute the minimum number of insertions, deletions and substitutions needed to turn one string into another (for example 'kitten' into 'sitting'). Define the state, base cases and recurrence, and give the time and space complexity, including how to reduce the space.

EasyTechnical
99 practiced

You can climb a staircase of n steps, taking 1 or 2 steps at a time. Write a function that returns the number of distinct ways to reach the top. State your recurrence and base cases, and give the time and space complexity of your version. Can you get the space down to constant?

That is every published Dynamic Programming question for AI Engineer so far. Browse the other topics in this category, or practice this one interactively.