Initialize the dp vector
var dp = Array . from ( Array ( N ) , ( ) => Array ( N ) ) ; for ( var i = 0 ; i < N ; i ++ ) for ( var j = 0 ; j < N ; j ++ ) dp [ i ] [ j ] = new Array ( 2 ) . fill ( - 1 ) ; document . write ( N - findLongestSubstring ( 0 , 0 , A , B , 1 , N , dp ) ) ; }