1138. Triangle — Minimum Path Sum Top to Bottom

EasyDynamic ProgrammingGrid DP

Given a triangle as a list of rows (row i has i+1 numbers), find the minimum path sum from top to bottom, where from index j in a row you may move to index j or j+1 in the next row. Return that minimum sum. The input is JSON {triangle}.

Input: JSON {triangle}.

Output: Integer — the minimum top-to-bottom path sum.

Examples

Example 1
Input: {"triangle":[[2],[3,4],[6,5,7],[4,1,8,3]]}
Output: 11
Explanation: 2+3+5+1 = 11.
Example 2
Input: {"triangle":[[-10]]}
Output: -10
Explanation: Single element.
Example 3
Input: {"triangle":[[1],[2,3]]}
Output: 3
Explanation: 1+2 = 3.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →