Mental model

First Rule of Dynamic Programming

Step 2 of 14
×

Make the state visible first

Before every DP question, slow down and make the state visible. When the state is clear, the transition becomes much less intimidating.

Do these four checks every single time and DP starts feeling mechanical instead of magical.

What changes?

indexrow / columnamountstaterange

What choices do I have?

take / skipmovesplitmatchbuy / sell

What is being asked?

maxmincountpossible or not

Where is the answer stored?

dp[n]dp[m][n]max(dp)state map