Find elements larger than half of the elements in an array | Set 2 | Function to find the element that are larger than half of elements of the array ; Find the value of mid ; Stores the maximum element ; Stores the frequency of each array element ; Traverse the array in the reverse order ; Decrement the value of count [ i ] and mid ; Prthe current element ; Check if the value of mid is equal to 0 ; Driver Code
def findLarger ( arr , n ) : NEW_LINE INDENT mid = ( n + 1 ) // 2 NEW_LINE mx = max ( arr ) NEW_LINE count = [ 0 ] * ( mx + 1 ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT count [ arr [ i ] ] += 1 NEW_LINE DEDENT for i in range ( mx , - 1 , - 1 ) : NEW_LINE INDENT while ( count [ i ] > 0 ) : NEW_LINE INDENT count [ i ] -= 1 NEW_LINE mid -= 1 NEW_LINE print ( i , end = " ▁ " ) NEW_LINE if ( mid == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( mid == 0 ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 10 , 4 , 2 , 8 , 9 ] NEW_LINE N = len ( arr ) NEW_LINE findLarger ( arr , N ) NEW_LINE DEDENT