Declare DP Array
var dp = new Array ( N + 2 ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( N + 2 ) . fill ( 0 ) ; } for ( var length = 1 ; length < N + 1 ; length ++ ) { for ( var left = 1 ; left < N - length + 2 ; left ++ ) { var right = left + length - 1 ;