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