Non | Efficient C # program to print all non - repeating elements . ; Insert all array elements in hash table ; Traverse through map only and using for - each loop for iteration over Map . entrySet ( ) ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void firstNonRepeating ( int [ ] arr , int n ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . ContainsKey ( arr [ i ] ) ) { var val = m [ arr [ i ] ] ; m . Remove ( arr [ i ] ) ; m . Add ( arr [ i ] , val + 1 ) ; } else { m . Add ( arr [ i ] , 1 ) ; } } foreach ( KeyValuePair < int , int > x in m ) { if ( x . Value == 1 ) { Console . Write ( x . Key + " ▁ " ) ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 9 , 4 , 9 , 6 , 7 , 4 } ; int n = arr . Length ; firstNonRepeating ( arr , n ) ; } }