As we have used smallest and second smallest , so we should now only check for n - 2 elements
for ( var i = 0 ; i < n - 1 ; i ++ ) { if ( ! hm . has ( second_smallest ) ) return false ; second_smallest += diff ; } return true ; }