

If the array given is 'TRIANGLE' = [[1], [2,3], [3,6,7], [8,9,6,1]] the triangle array will look like:
1
2,3
3,6,7
8,9,6,10
For the given triangle array the minimum sum path would be 1->2->3->8. Hence the answer would be 14.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
The first line of each test case contains an integer ‘N’ representing the length of the array/list triangle.
Then N lines follow. Each of the ith row contains i + 1 space-separated integers denoting the elements of the array/list 'TRIANGLE'.
For each test case, print an integer X representing the minimum path sum.
Output for each test case will be printed in a separate line.
You don’t need to take input or print anything, it already has been taken care of. Just implement the function.
1 <= T <= 5
1 <= N <= 10^3
-10^6 <= TRIANGLE[i][pos] <= 10^6 ,
Where 'TRIANGLE[i][pos]' is the element at row = 'i' & position = 'pos' in triangle array.
Time limit: 1 sec
We can check all the paths from top to bottom using recursion.
The algorithm will be:
We can optimize the brute force recursive approach using memoization. We can start from the top row, and store the result for every step in an array. Whenever we get the repeating problem, we can use the stored result instead of calculating again.
Below are the steps:
We can make two dimensional ‘DP’ table and we know the base cases as now we are filling our 'DP' table in a bottom-up manner.
Below are the steps :
Note: 'DP[0][0]’ gives the result in bottom-up fashion.
We can make a 1D ‘DP’ array and update it using the bottom-up approach.
Below are the steps :