--- task_categories: - text-generation - text2text-generation language: - en tags: - code pretty_name: GeeksForGeeks Problems size_categories: - 1K using namespace std; // Function to check if the given // string is bitonic int checkBitonic(string s) { int i, j; // Check for increasing sequence for (i = 1; i < s.size(); i++) { if (s[i] > s[i - 1]) continue; if (s[i] <= s[i - 1]) break; } // If end of string has been reached if (i == s.size() - 1) return 1; // Check for decreasing sequence for (j = i + 1; j < s.size(); j++) { if (s[j] < s[j - 1]) continue; if (s[j] >= s[j - 1]) break; } i = j; // If the end of string hasn't // been reached if (i != s.size()) return 0; // Return true if bitonic return 1; } // Driver Code int main() { // Given string string s = "abcdfgcba"; // Function Call (checkBitonic(s) == 1) ? cout << "YES" : cout << "NO"; return 0; } ''' Java ''' // Java program for the above approach import java.util.*; class GFG{ // Function to check if the given // String is bitonic static int checkBitonic(char []s) { int i, j; // Check for increasing sequence for(i = 1; i < s.length; i++) { if (s[i] > s[i - 1]) continue; if (s[i] <= s[i - 1]) break; } // If end of String has been reached if (i == s.length - 1) return 1; // Check for decreasing sequence for(j = i + 1; j < s.length; j++) { if (s[j] < s[j - 1]) continue; if (s[j] >= s[j - 1]) break; } i = j; // If the end of String hasn't // been reached if (i != s.length) return 0; // Return true if bitonic return 1; } // Driver Code public static void main(String[] args) { // Given String String s = "abcdfgcba"; // Function Call System.out.print((checkBitonic( s.toCharArray()) == 1) ? "YES" : "NO"); } } // This code is contributed by PrinciRaj1992 ''' Python3 ''' # Python3 program for the above approach # Function to check if the given # string is bitonic def checkBitonic(s): i = 0 j = 0 # Check for increasing sequence for i in range(1, len(s)): if (s[i] > s[i - 1]): continue; if (s[i] <= s[i - 1]): break; # If end of string has been reached if (i == (len(s) - 1)): return True; # Check for decreasing sequence for j in range(i + 1, len(s)): if (s[j] < s[j - 1]): continue; if (s[j] >= s[j - 1]): break; i = j; # If the end of string hasn't # been reached if (i != len(s) - 1): return False; # Return true if bitonic return True; # Driver code # Given string s = "abcdfgcba" # Function Call if(checkBitonic(s)): print("YES") else: print("NO") # This code is contributed by grand_master ''' C# ''' // C# program for the above approach using System; class GFG{ // Function to check if the given // String is bitonic static int checkBitonic(char []s) { int i, j; // Check for increasing sequence for(i = 1; i < s.Length; i++) { if (s[i] > s[i - 1]) continue; if (s[i] <= s[i - 1]) break; } // If end of String has been reached if (i == s.Length - 1) return 1; // Check for decreasing sequence for(j = i + 1; j < s.Length; j++) { if (s[j] < s[j - 1]) continue; if (s[j] >= s[j - 1]) break; } i = j; // If the end of String hasn't // been reached if (i != s.Length) return 0; // Return true if bitonic return 1; } // Driver Code public static void Main(String[] args) { // Given String String s = "abcdfgcba"; // Function call Console.Write((checkBitonic( s.ToCharArray()) == 1) ? "YES" : "NO"); } } // This code is contributed by PrinciRaj1992 ''' Javascript ''' ''' Output: YES Time Complexity: O(N) Auxiliary Space: O(1) ```