loading

Triangle — Step-by-Step Visualization

mediumLeetCode #120ArrayDynamic Programming

Return minimum path sum from top to bottom in triangle.

Algorithm Pattern

Bottom-Up DP

Key Idea

Work from bottom up. Each cell = its value + min of two cells below.

Step-by-Step Approach

  1. Initialize dp as bottom row
  2. For each row from second-to-last upward:
  3. dp[j] = triangle[i][j] + min(dp[j], dp[j+1])
  4. Return dp[0]

Related Problems