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 || abs ( arr1 [ i ] - largest ) > k ) count ++ ; }