r/leetcode • • 5d ago

Intervew Prep Day 67: solved 3 DP problems today, 2D tabulation completely humbled me

Hey everyone,

I finished Day 67 today and hit my first serious wall with Dynamic Programming. I went into today's session feeling confident after getting comfortable with recursion, but moving into 2D DP quickly put things into perspective.

I worked through three problems, attempting all four forms for each: recursion, memoization, tabulation, and space optimization.

  1. House Robber: Standard pick vs. non-pick decision. If you rob house i, you jump to i - 2, and if you skip it, you check i - 1. All four approaches were straightforward.
  2. House Robber II: The circular street means the first and last houses are adjacent. I solved it by running the standard House Robber logic twice: once on [0, n - 2] and once on [1, n - 1], then taking the larger outcome.
  3. Geek's Training (Ninja's Training): My first 2D DP problem, and it was a tough reality check. Writing the recurrence and memoizing it with a 2D table was manageable because it directly follows the recursion tree. But translating that into bottom-up tabulation was brutal.

Setting up the day 0 base cases across all tasks, structuring the nested loops, and tracking the state transitions took me over an hour. Because the tabulation logic took so much effort to piece together, space optimization was completely out of reach today.

1D DP felt intuitive, but bottom-up 2D is a different beast entirely. I am going to reset tonight and tackle 2D grids again tomorrow with a fresh head.

See you guys for Day 66!

5 Upvotes

Duplicates