Non | Efficient CPP program to print all non - repeating elements . ; Insert all array elements in hash table ; Traverse through map only and ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void firstNonRepeating ( int arr [ ] , int n ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp [ arr [ i ] ] ++ ; for ( auto x : mp ) if ( x . second == 1 ) cout << x . first << " ▁ " ; } int main ( ) { int arr [ ] = { 9 , 4 , 9 , 6 , 7 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; firstNonRepeating ( arr , n ) ; return 0 ; }