Skip to content
Discussion options

You must be logged in to vote

We need to find the minimum path sum from the top to the bottom of a given triangle array. Each step allows moving to an adjacent number in the row below, either to the same index or the next index. The goal is to compute the minimum sum efficiently using dynamic programming with optimal space complexity.

Approach

  1. Dynamic Programming (Bottom-Up): We start from the bottom row of the triangle and work our way up. For each element in the current row, we update its value by adding the minimum of the two adjacent elements from the row below. This way, each element in the current row will store the minimum path sum from that element to the bottom.
  2. Space Optimization: Instead of using extra spa…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Sep 25, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Sep 25, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants