Count of Reverse Bitonic Substrings in a given String | C # program to implement the above approach ; Function to calculate the number of reverse bitonic substrings ; Stores the count ; All possible lengths of substrings ; Starting point of a substring ; Ending point of a substring ; Condition for reverse bitonic substrings of length 1 ; Check for decreasing sequence ; If end of substring is reached ; For increasing sequence ; If end of substring is reached ; Return the number of bitonic substrings ; Driver code
using System ; class GFG { public static int CountsubString ( char [ ] str , int n ) { int c = 0 ; for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; char temp = str [ i ] , f = '0' ; if ( j == i ) { c ++ ; continue ; } int k = i + 1 ; while ( temp > str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; } if ( k > j ) { c ++ ; f = '2' ; } while ( k <= j && temp < str [ k ] && f != '2' ) { temp = str [ k ] ; k ++ ; } if ( k > j && f != 2 ) { c ++ ; f = '0' ; } } } return c ; } public static void Main ( String [ ] args ) { char [ ] str = { ' b ' , ' a ' , ' d ' , ' e ' } ; Console . WriteLine ( CountsubString ( str , str . Length ) - 1 ) ; } }