Number of shortest paths to reach every cell from bottom | Function to find number of shortest paths ; Compute the grid starting from the bottom - left corner ; Prvar the grid ; Driver code ; Function call
function NumberOfShortestPaths ( n , m ) { var a = Array ( n ) . fill ( ) . map ( ( ) => Array ( m ) . fill ( 0 ) ) ; for ( var i = n - 1 ; i >= 0 ; i -- ) { for ( j = 0 ; j < m ; j ++ ) { if ( j == 0 i == n - 1 ) a [ i ] [ j ] = 1 ; else a [ i ] [ j ] = a [ i ] [ j - 1 ] + a [ i + 1 ] [ j ] ; } } for ( var i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { document . write ( a [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } var n = 5 , m = 2 ; NumberOfShortestPaths ( n , m ) ;