thecodingcompany
DSA Pattern

Dynamic Programming

The pattern most candidates skip — and the one that decides offers.

Problems5
FocusPattern + approach

5 problems

Attempt each problem before reading the approach. In the interview, state the pattern and complexity out loud first — that is what earns the marks.

01Climbing StairsEasy1-D DP
ProblemCount the distinct ways to reach step n taking 1 or 2 steps at a time.
Approach. It is Fibonacci. Keep two rolling variables to get O(1) space.
02Coin ChangeMedium1-D DP
ProblemReturn the fewest coins needed to make an amount, or −1 if impossible.
Approach. dp[i] = min over coins of dp[i − coin] + 1. Initialise with infinity, dp[0] = 0.
03Longest Common SubsequenceMedium2-D DP
ProblemFind the length of the longest subsequence common to two strings.
Approach. A 2-D table: on a match take 1 + diagonal, otherwise the max of the top and left cells.
040/1 KnapsackMediumKnapsack
ProblemMaximise value within a capacity, taking each item at most once.
Approach. Iterate items and capacities backwards so each item is used once, filling a 1-D dp array.
05Edit DistanceHard2-D DP
ProblemFind the minimum insertions, deletions and replacements to convert one string to another.
Approach. 2-D DP where a character match costs the diagonal value and a mismatch costs 1 + min of the three neighbours.

Practise here. Get placed there.

Prep+ is unlimited practice. When you are ready to turn it into an offer, TCC Placement Partner handles portfolio, resume and interviews.