Count array elements exceeding all previous elements as well as the next array element | Function to count array elements satisfying the given condition ; If there is only one array element ; Traverse the array ; Update the maximum element encountered so far ; Count the number of array elements strictly greater than all previous and immediately next elements ; Print the count ; Given array ; Size of the array
function numberOfIntegers ( arr , N ) { let cur_max = 0 , count = 0 ; if ( N == 1 ) { count = 1 ; } else { for ( let i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] > cur_max ) { cur_max = arr [ i ] ; if ( arr [ i ] > arr [ i + 1 ] ) { count ++ ; } } } if ( arr [ N - 1 ] > cur_max ) count ++ ; } document . write ( count ) ; } let arr = [ 1 , 2 , 0 , 7 , 2 , 0 , 2 , 0 ] ; let N = arr . length ; numberOfIntegers ( arr , N ) ;