Minimum Sum Path in a Triangle | JavaScript program for Dynamic Programming implementation of Min Sum Path in a Triangle ; Util function to find minimum sum for a path ; For storing the result in a 1 - D array , and simultaneously updating the result . ; For the bottom row ; Calculation of the remaining rows , in bottom up manner . ; Return the top element ; Driver code
let A = [ [ 2 ] , [ 3 , 9 ] , [ 1 , 6 , 7 ] ] ; function minSumPath ( ) { let memo = [ ] ; let n = A . length - 1 ; for ( let i = 0 ; i < A [ n ] . length ; i ++ ) memo [ i ] = A [ n ] [ i ] ; for ( let i = A . length - 2 ; i >= 0 ; i -- ) for ( let j = 0 ; j < A [ i ] . length ; j ++ ) memo [ j ] = A [ i ] [ j ] + Math . min ( memo [ j ] , memo [ j + 1 ] ) ; return memo [ 0 ] ; } document . write ( minSumPath ( ) ) ;