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
def numberOfIntegers ( arr , N ) : NEW_LINE INDENT cur_max = 0 NEW_LINE count = 0 NEW_LINE if ( N == 1 ) : NEW_LINE INDENT count = 1 NEW_LINE DEDENT else : NEW_LINE INDENT for i in range ( N - 1 ) : NEW_LINE INDENT if ( arr [ i ] > cur_max ) : NEW_LINE INDENT cur_max = arr [ i ] NEW_LINE if ( arr [ i ] > arr [ i + 1 ] ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT if ( arr [ N - 1 ] > cur_max ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT print ( count ) NEW_LINE DEDENT arr = [ 1 , 2 , 0 , 7 , 2 , 0 , 2 , 0 ] NEW_LINE N = len ( arr ) NEW_LINE numberOfIntegers ( arr , N ) NEW_LINE