core practice · coding problem
Maximum Subarray
LeetCode #53 — Maximum Subarray. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/maximum-subarray/
The mechanism
Dynamic programming is recursion with the repeated work cached. Define the state (what does dp[i] mean?), the recurrence (how does dp[i] build on earlier states?), and the base case. 1D DP means the state is a single index along a sequence.
Expected evidence
Pass all LeetCode test cases for this problem.
Try this drill in the practice workspace →
Hints when you need them
- Pattern hint: dp 1d.
- Start with brute force, then optimize time/space.
- Write down invariants before coding.
Watch for these mistakes
- Starting to code before clearly defining what dp[i] represents
- Wrong iteration order so a state is read before it is computed
- Missing or wrong base cases