Count of array elements which are greater than all elements on its left | Function to return the count of array elements with all elements to its left smaller than it ; Stores the count ; Stores the maximum ; Iterate over the array ; If an element greater than maximum is obtained ; Increase count ; Update maximum ; Driver Code
def count_elements ( arr ) : NEW_LINE INDENT count = 1 NEW_LINE max = arr [ 0 ] NEW_LINE for i in range ( 1 , len ( arr ) ) : NEW_LINE INDENT if arr [ i ] > max : NEW_LINE INDENT count += 1 NEW_LINE max = arr [ i ] NEW_LINE DEDENT DEDENT return count NEW_LINE DEDENT arr = [ 2 , 1 , 4 , 6 , 3 ] NEW_LINE print ( count_elements ( arr ) ) NEW_LINE