Count of bitonic substrings from the given string | Function to find all the bitonic sub strings ; Pick starting po ; Iterate till length of the string ; Pick ending pofor string ; Substring from i to j is obtained ; Substrings of length 1 ; Increase count ; For increasing sequence ; Check for strictly increasing ; Increase count ; Check for decreasing sequence ; Increase count ; Print the result ; Given string ; Function Call
def subString ( str , n ) : NEW_LINE INDENT c = 0 ; NEW_LINE for len in range ( 1 , n + 1 ) : NEW_LINE INDENT for i in range ( 0 , n - len + 1 ) : NEW_LINE INDENT j = i + len - 1 ; NEW_LINE temp = str [ 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 < str [ k ] ) : NEW_LINE INDENT temp = str [ k ] ; NEW_LINE k += 1 ; NEW_LINE f = 2 ; NEW_LINE DEDENT if ( k > j ) : NEW_LINE INDENT c += 1 ; NEW_LINE f = 2 ; NEW_LINE DEDENT while ( k <= j and temp > str [ k ] and f != 2 ) : NEW_LINE INDENT k += 1 ; NEW_LINE f = 0 ; 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 str = " bade " ; NEW_LINE subString ( str , len ( str ) ) NEW_LINE