Count of all possible reverse bitonic subarrays | Function that counts all the reverse bitonic subarray in arr [ ] ; To store the count of reverse bitonic subarray ; Iterate the array and select the starting element ; Iterate for selecting the ending element for subarray ; Subarray arr [ i to j ] ; For 1 length , increment the count and continue ; For Decreasing Subarray ; Check if only Decreasing ; For Increasing Subarray ; Print the total count of subarrays ; Given array arr [ ] ; Function Call
def countReversebitonic ( arr , n ) : NEW_LINE INDENT c = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i , n ) : NEW_LINE INDENT temp = arr [ i ] NEW_LINE f = 0 ; NEW_LINE if ( j == i ) : NEW_LINE INDENT c += 1 ; NEW_LINE continue ; NEW_LINE DEDENT k = i + 1 ; NEW_LINE while ( k <= j and temp > arr [ k ] ) : NEW_LINE INDENT temp = arr [ k ] ; NEW_LINE k += 1 ; NEW_LINE DEDENT if ( k > j ) : NEW_LINE INDENT c += 1 ; NEW_LINE f = 2 ; NEW_LINE DEDENT while ( k <= j and temp < arr [ k ] and f != 2 ) : NEW_LINE INDENT temp = arr [ k ] ; NEW_LINE k += 1 ; NEW_LINE DEDENT if ( k > j and f != 2 ) : NEW_LINE INDENT c += 1 ; NEW_LINE f = 0 ; NEW_LINE DEDENT DEDENT DEDENT print ( c ) NEW_LINE DEDENT arr = [ 2 , 3 , 1 , 4 ] ; NEW_LINE countReversebitonic ( arr , len ( arr ) ) ; NEW_LINE