pattern / HARD
Solve complex problems by breaking into subproblems
complexity
time
Varies (O(n) to O(n²) typically)
space
Same as time
02' — visual
interactive
Maximum sum subarray
03'
mental
model.
Define state, recurrence, base cases. Build up from base cases (bottom-up) or recurse with memoization (top-down).
DP solves problems by storing results of subproblems to avoid recomputation. Top-down (memoization) or bottom-up (tabulation).
when to use ✓
when not ✗
04'
Overlapping subproblems
Optimal substructure
Choices at each step
Brute force is exponential
05'
1# Beginner: Fixed-size sliding window2def max_sum_k(nums, k):3 n = len(nums)4 if n < k:5 return 06 window_sum = sum(nums[:k])7 max_sum = window_sum8 for i in range(k, n):9 window_sum += nums[i] - nums[i - k]10 max_sum = max(max_sum, window_sum)11 return max_sum
common mistakes
interview tips
06'
0 curated problems from LeetCode
No questions found for this pattern yet.
07'