table [ i ] will store the minimum number of elements from the array to form i
var table = Array ( ( 2 * max ) + 1 ) . fill ( 0 ) ; table [ 0 ] = 0 ; for ( i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) table [ i ] = Number . MAX_VALUE ; var ans = - 1 ;