Check if a given string is a Reverse Bitonic String or not | Java program to implement the above approach ; Function to check if the given string is reverse bitonic ; Check for decreasing sequence ; If end of string has been reached ; Check for increasing sequence ; If the end of string hasn 't been reached ; If the string is reverse bitonic ; Driver Code
class GFG { static int checkReverseBitonic ( String s ) { int i , j ; for ( i = 1 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) < s . charAt ( i - 1 ) ) continue ; if ( s . charAt ( i ) >= s . charAt ( i - 1 ) ) break ; } if ( i == s . length ( ) - 1 ) return 1 ; for ( j = i + 1 ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( j ) > s . charAt ( j - 1 ) ) continue ; if ( s . charAt ( j ) <= s . charAt ( j - 1 ) ) break ; } i = j ; if ( i != s . length ( ) ) return 0 ; return 1 ; } public static void main ( String [ ] args ) { String s = " abcdwef " ; if ( checkReverseBitonic ( s ) == 1 ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }