Check if absolute difference of smallest and arr1 [ i ] or largest and arr1 [ i ] is > K then arr [ i ] is a required element
if ( abs ( arr1 [ i ] - smallest ) > k or abs ( arr1 [ i ] - largest ) > k ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT