If we 're not at the  above, we can consider  the above value.
if ( i > 0 ) { int tempMax = Math . max ( maxPath [ i - 1 ] [ j ] * arr [ i ] [ j ] , minPath [ i - 1 ] [ j ] * arr [ i ] [ j ] ) ; maxVal = Math . max ( maxVal , tempMax ) ; int tempMin = Math . min ( maxPath [ i - 1 ] [ j ] * arr [ i ] [ j ] , minPath [ i - 1 ] [ j ] * arr [ i ] [ j ] ) ; minVal = Math . min ( minVal , tempMin ) ; }