Creating a DP array to keep count of max score at ith element and it will be filled in the bottom Up manner
let dp = new Array ( Math . max ( ... a ) + 1 ) ; dp [ 0 ] = 0 ; dp [ 1 ] = freq . get ( 1 ) ;