LeetEye LeetEye
Cheat Sheet

2-D DP Cheat Sheet

Quick reference for coding interviews. Bookmark this page!

What is 2-D DP?

Tackle grid and matrix problems with two-dimensional DP.

Trigger Words

When you see these in a problem, think 2-D DP:

unique paths 2d-dp longest common subsequence best time to buy and sell stock with cooldown coin change ii target sum interleaving string edit distance burst balloons

Template Code

def uniquePaths(m: int, n: int) -> int:
    # Space-optimized 1D DP
    dp = [1] * n
    
    for i in range(1, m):
        for j in range(1, n):
            dp[j] += dp[j - 1]
    
    return dp[n - 1]

Complexity

Typical Time O(m × n)
Typical Space O(n)

Common Variations

  • Basic 2-D DP
  • 2-D DP with constraints
  • Optimized 2-D DP

Practice Problems

See all 2-D DP problems →

Practice 2-D DP

Learn to recognize patterns instantly with interactive MCQs.

Download LeetEye Free
Practice in LeetEye