Storing occurrences of each element
Dictionary < int , int > map = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! map . ContainsKey ( a [ i ] ) ) map . Add ( a [ i ] , 1 ) ; }