Count of bitonic substrings from the given string | Java + program for the above approach ; Function to find all the bitonic sub Strings ; Pick starting point ; Iterate till length of the String ; Pick ending point for 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 ; Driver Code ; Given String ; Function call
import java . util . * ; class GFG { static void subString ( 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 ( k < n && temp < str [ k ] ) { temp = str [ k ] ; k ++ ; f = 2 ; } if ( k > j ) { c ++ ; f = 2 ; } while ( k < n && temp > str [ k ] && f != 2 ) { k ++ ; f = 0 ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } System . out . print ( c + "NEW_LINE"); } public static void main ( String [ ] args ) { char str [ ] = " bade " . toCharArray ( ) ; subString ( str , str . length ) ; } }