Largest Non | Python 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 ; Prlargest non - repeating element ; Driver Code
import sys NEW_LINE def LarUnEl ( arr , N ) : NEW_LINE INDENT map = dict . fromkeys ( arr , 0 ) ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT map [ arr [ i ] ] += 1 ; NEW_LINE DEDENT LNRElem = - sys . maxsize ; NEW_LINE ind = - 1 ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( map . get ( arr [ i ] ) == 1 and arr [ i ] > LNRElem ) : NEW_LINE INDENT ind = i ; NEW_LINE LNRElem = arr [ i ] ; NEW_LINE DEDENT DEDENT if ( ind == - 1 ) : NEW_LINE INDENT print ( ind ) ; NEW_LINE return ; NEW_LINE DEDENT print ( arr [ ind ] ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 1 , 8 , 8 , 4 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE LarUnEl ( arr , N ) ; NEW_LINE DEDENT