AlgoMaster Logo

Triangle

Ashish

Ashish Pratap Singh

medium

Problem Description

Solve it on LeetCode

Approaches

1. Recursive Brute Force

Intuition:

Start from the top of the triangle, at each step, move to one of the two adjacent numbers on the row below. Sum the paths and return the minimum path sum recursively.

Code:

2. Memoization

Intuition:

To avoid recalculating the same values, we store the results of subproblems in a memoization table.

Code:

3. Bottom-Up Dynamic Programming

Intuition:

Start filling the DP table from the bottom of the triangle towards the top, by considering the potential next moves in the row below.

Code:

4. Space Optimized Dynamic Programming

Intuition:

Instead of keeping a full DP table, keep a single array representing the current row computations, reducing space usage.

Code: