Triangle

Solution Code
class Solution:def minimumTotal(self, triangle: list[list[int]]) -> int:n = len(triangle)dp = list(triangle[-1])for i in range(n - 2, -1, -1):for j in range(i + 1):dp[j] = triangle[i][j] + min(dp[j], dp[j + 1])return dp[0]

Time Complexity

O(N^2) where N is the number of rows in the triangle.

Space Complexity

O(N) where N is the number of rows in the triangle.