Initialise the dp array
let dp = new Array ( n ) ; for ( var i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( 2 ) ; } for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < 2 ; j ++ ) { dp [ i ] [ j ] = 1e6 ; } }