Largest number in the Array having frequency same as value | Function to find the largest number whose frequency is equal to itself . ; Adding 65536 to keep the count of the current number ; Right shifting by 16 bits to find the count of the number i ; Driver code
def findLargestNumber ( arr , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT arr [ i ] &= 0xFFFF ; NEW_LINE if ( arr [ i ] <= n ) : NEW_LINE INDENT arr [ i ] += 0x10000 ; NEW_LINE DEDENT DEDENT for i in range ( n - 1 , 0 , - 1 ) : NEW_LINE INDENT if ( ( arr [ i ] >> 16 ) == i ) : NEW_LINE INDENT return i + 1 ; NEW_LINE DEDENT DEDENT return - 1 ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 2 , 5 , 5 , 2 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE print ( findLargestNumber ( arr , n ) ) ; NEW_LINE DEDENT