Count of Reverse Bitonic Substrings in a given String | Function to calculate the number of reverse bitonic substrings ; Stores the count ; All possible lengths of substrings ; Starting poof a substring ; Ending poof a substring ; Condition for reverse bitonic substrings of length 1 ; Check for decreasing sequence ; If end of substring is reache ; For increasing sequence ; If end of substring is reached ; Return the number of bitonic substrings ; Driver Code
def CountsubString ( strr , n ) : NEW_LINE INDENT c = 0 NEW_LINE for len in range ( n + 1 ) : NEW_LINE INDENT for i in range ( n - len ) : NEW_LINE INDENT j = i + len - 1 NEW_LINE temp = strr [ 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 > strr [ k ] ) : NEW_LINE INDENT temp = strr [ 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 f != 2 and temp < strr [ k ] ) : NEW_LINE INDENT temp = strr [ 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 return c NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT strr = " bade " NEW_LINE print ( CountsubString ( strr , len ( strr ) ) ) NEW_LINE DEDENT