Largest Non | Function to find the largest unique element of the array ; Store frequency of each distinct array element ; Traverse the array ; Update frequency of arr [ i ] ; Stores largest non - repeating element present in the array ; Stores index of the largest unique element of the array ; 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 the largest non - repeating element ; Driver Code
function LarUnEl ( arr , N ) { var mp = new Map ( ) ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . has ( arr [ i ] ) ) mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) else mp . set ( arr [ i ] , 1 ) ; } var LNRElem = - 1000000000 ; var ind = - 1 ; for ( var i = 0 ; i < N ; i ++ ) { if ( mp . get ( arr [ i ] ) == 1 && arr [ i ] > LNRElem ) { ind = i ; LNRElem = arr [ i ] ; } } if ( ind == - 1 ) { cout << ind ; return ; } document . write ( arr [ ind ] ) ; } var arr = [ 3 , 1 , 8 , 8 , 4 ] ; var N = arr . length ; LarUnEl ( arr , N ) ;