Store all the elements in the map to use map as hash for finding elements in O ( 1 ) time .
Dictionary < int , bool > occ = new Dictionary < int , bool > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { occ [ arr [ i ] ] = true ; } bool isPairFound = false ; for ( int i = 0 ; i < n ; i ++ ) {