Largest Non | C # program to implement the above approach ; Function to find the largest unique element of the array ; Store frequency of each distinct element of the array ; Traverse the array ; Update frequency of arr [ i ] ; Stores largest non - repeating element present in the array ; Stores index of the largest non - repeating array element ; Traverse the array ; If frequency of arr [ i ] is equal to 1 and arr [ i ] exceeds LNRElem ; Update ind ; Update LNRElem ; If no array element is found with frequency equal to 1 ; Print largest non - repeating element ; Drivers Code
using System ; using System . Collections . Generic ; class GFG { static void LarUnEl ( int [ ] arr , int N ) { Dictionary < int , int > map = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( map . ContainsKey ( arr [ i ] ) == true ) map [ arr [ i ] ] += 1 ; else map [ arr [ i ] ] = 1 ; } int LNRElem = Int32 . MinValue ; int ind = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { if ( map [ arr [ i ] ] == 1 && arr [ i ] > LNRElem ) { ind = i ; LNRElem = arr [ i ] ; } } if ( ind == - 1 ) { Console . WriteLine ( ind ) ; return ; } Console . WriteLine ( arr [ ind ] ) ; } public static void Main ( ) { int [ ] arr = { 3 , 1 , 8 , 8 , 4 } ; int N = arr . Length ; LarUnEl ( arr , N ) ; } }