assign - 1 to all positions
for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( maximum ) ; for ( let j = 0 ; j < dp [ i ] . length ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } document . write ( " " + lcs ( X , Y , m , n , dp ) ) ;