For each element arr [ i ] , see if there is another element with vaalue sum - arr [ i ]
HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int val = sum - arr [ i ] ;