Triangle
Given a triangle array where row i has i+1 numbers, return the minimum path sum from the top to the bottom. From index j in a row you may move to index j or index j+1 in the next row (adjacent numbers below).
Open official problem prompt ↗Find the cheapest way to descend from the single top element to the bottom row, stepping only to adjacent elements each level.
Picture water starting at the peak of a pyramid, at each step trickling to one of the two stones immediately below. You want the route where the summed weights of stones touched is smallest.
- Input
- triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
- Output
- 11
- Why
- The path 2 -> 3 -> 5 -> 1 sums to 11, the smallest top-to-bottom total.
1 <= triangle.length <= 200triangle[0].length == 1triangle[i].length == triangle[i-1].length + 1-10^4 <= triangle[i][j] <= 10^4