Stores the dp states where dp [ i ] [ j ] represents count of arrays of length i + 1 having their last element as j
let dp = new Array ( N ) ; for ( let i = 0 ; i < dp . length ; i ++ ) { dp [ i ] = new Array ( M + 2 ) . fill ( 0 ) ; }