Construct hash for negative elements
for ( let i = 0 ; i <= n - 1 ; i ++ ) { if ( arr [ i ] < 0 ) { if ( hashNegative . has ( Math . abs ( arr [ i ] ) ) ) { hashNegative . set ( Math . abs ( arr [ i ] ) , hashNegative . get ( Math . abs ( arr [ i ] ) ) + 1 ) ; } else { hashNegative . set ( Math . abs ( arr [ i ] ) , 1 ) ; } } }