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
function count_elements ( arr , n ) { let count = 1 ; let max = arr [ 0 ] ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { count += 1 ; max = arr [ i ] ; } } return count ; } let arr = [ 2 , 1 , 4 , 6 , 3 ] ; let n = arr . length ; document . write ( count_elements ( arr , n ) ) ;