Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to either index i or index i + 1 on the next row.
Example 1
Input: triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
Output: 11
Explanation: The path 2 → 3 → 5 → 1 moves to an adjacent number on each row and sums to 11. Every other path is more expensive.
Example 2
Input: triangle = [[-10]]
Output: -10
Explanation: The triangle has a single number, so the path sum is -10.
Example 3
Input: triangle = [[1],[2,3]]
Output: 3
Explanation: From 1 the path can go to 2 or 3. Choosing 2 gives the minimum, 1 + 2 = 3.
Work upward from the bottom row. Replace each cell with itself plus the smaller of the two cells directly beneath it. After collapsing every row, the apex holds the minimum top-to-bottom path sum.
Run checks all cases above. Submit evaluates all test cases.