Maximum decimal value path in a binary matrix | JavaScript program to find maximum decimal value path in binary matrix ; Returns maximum decimal value in binary matrix . Here p indicate power of 2 ; Out of matrix boundary ; If current matrix value is 1 then return result + power ( 2 , p ) else result ; Driver Code
let N = 4 ; function maxDecimalValue ( mat , i , j , p ) { if ( i >= N j >= N ) { return 0 ; } let result = Math . max ( maxDecimalValue ( mat , i , j + 1 , p + 1 ) , maxDecimalValue ( mat , i + 1 , j , p + 1 ) ) ; if ( mat [ i ] [ j ] == 1 ) { return ( Math . pow ( 2 , p ) + result ) ; } else { return result ; } } let mat = [ [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 0 ] , [ 1 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 ] ] ; document . write ( maxDecimalValue ( mat , 0 , 0 , 0 ) ) ;