Check if a given string is Even-Odd Palindrome or not Last Updated : 10 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Given a string str, the task is to check if the given string is Even-Odd Palindrome or not. An Even-Odd Palindrome string is defined to be a string whose characters at even indices form a Palindrome while the characters at odd indices also form a Palindrome separately. Examples: Input: str="abzzab" Output:YES Explanation: String formed by characters at odd indices: bzb, which is a Palindrome. String formed by characters at even indices: aza, which is a Palindrome. Hence, the given string is an Even-Odd Palindrome.Input: str="daccad" Output: NO Approach: To solve the problem, create a new String by appending the Odd Indexed Characters of the given string and check if the strings formed are palindromic or not. Similarly, check for Even Indexed Characters. If both the strings are palindromic, then print “Yes”. Otherwise, print “No”.Below is the implementation of the above approach: C++ // C++ program to implement // the above approach #include <bits/stdc++.h> using namespace std; // Function to check if the string // str is palindromic or not bool isPalindrome(string str) { // Pointers to iterate the // string from both ends int l = 0; int h = str.size() - 1; while (h > l) { // If characters are found // to be distinct if (str[l++] != str[h--]) { return false; } } // Return true if the // string is palindromic return true; } // Function to generate string // from characters at odd indices string makeOddString(string str) { string odd = ""; for (int i = 1; i < str.size(); i += 2) { odd += str[i]; } return odd; } // Function to generate string // from characters at even indices string makeevenString(string str) { string even = ""; for (int i = 0; i < str.size(); i += 2) { even += str[i]; } return even; } // Functions to checks if string // is Even-Odd Palindrome or not void checkevenOddPalindrome(string str) { // Generate odd indexed string string odd = makeOddString(str); // Generate even indexed string string even = makeevenString(str); // Check for Palindrome if (isPalindrome(odd) && isPalindrome(even)) cout << "Yes" << endl; else cout << "No" << endl; } // Driver Code int main() { string str = "abzzab"; checkevenOddPalindrome(str); return 0; } Java // Java program implementation // of the approach import java.util.*; import java.io.*; class GFG{ // Function to check if the string // str is palindromic or not static boolean isPalindrome(String str) { // Pointers to iterate the // string from both ends int l = 0; int h = str.length() - 1; while (h > l) { // If characters are found // to be distinct if (str.charAt(l++) != str.charAt(h--)) return false; } // Return true if the // string is palindromic return true; } // Function to generate string // from characters at odd indices static String makeOddString(String str) { String odd = ""; for(int i = 1; i < str.length(); i += 2) { odd += str.charAt(i); } return odd; } // Function to generate string // from characters at even indices static String makeevenString(String str) { String even = ""; for(int i = 0; i < str.length(); i += 2) { even += str.charAt(i); } return even; } // Functions to checks if string // is Even-Odd Palindrome or not static void checkevenOddPalindrome(String str) { // Generate odd indexed string String odd = makeOddString(str); // Generate even indexed string String even = makeevenString(str); // Check for Palindrome if (isPalindrome(odd) && isPalindrome(even)) System.out.println("Yes"); else System.out.println("No"); } // Driver code public static void main(String[] args) { String str = "abzzab"; checkevenOddPalindrome(str); } } // This code is contributed by sanjoy_62 Python3 # Python3 program to implement # the above approach # Function to check if the string # str is palindromic or not def isPalindrome(Str): # Pointers to iterate the # string from both ends l = 0 h = len(Str) - 1 while (h > l): # If characters are found # to be distinct if (Str[l] != Str[h]): return False l += 1 h -= 1 # Return true if the # string is palindromic return True # Function to generate string # from characters at odd indices def makeOddString(Str): odd = "" for i in range(1, len(Str), 2): odd += Str[i] return odd # Function to generate string # from characters at even indices def makeevenString(Str): even = "" for i in range(0, len(Str), 2): even += Str[i] return even # Functions to checks if string # is Even-Odd Palindrome or not def checkevenOddPalindrome(Str): # Generate odd indexed string odd = makeOddString(Str) # Generate even indexed string even = makeevenString(Str) # Check for Palindrome if (isPalindrome(odd) and isPalindrome(even)): print("Yes") else: print("No") # Driver code Str = "abzzab" checkevenOddPalindrome(Str) # This code is contributed by himanshu77 C# // C# program implementation // of the approach using System; class GFG{ // Function to check if the string // str is palindromic or not static bool isPalindrome(string str) { // Pointers to iterate the // string from both ends int l = 0; int h = str.Length - 1; while (h > l) { // If characters are found // to be distinct if (str[l++] != str[h--]) return false; } // Return true if the // string is palindromic return true; } // Function to generate string // from characters at odd indices static string makeOddString(string str) { string odd = ""; for(int i = 1; i < str.Length; i += 2) { odd += str[i]; } return odd; } // Function to generate string // from characters at even indices static string makeevenString(string str) { string even = ""; for(int i = 0; i < str.Length; i += 2) { even += str[i]; } return even; } // Functions to checks if string // is Even-Odd Palindrome or not static void checkevenOddPalindrome(string str) { // Generate odd indexed string string odd = makeOddString(str); // Generate even indexed string string even = makeevenString(str); // Check for Palindrome if (isPalindrome(odd) && isPalindrome(even)) Console.WriteLine("Yes"); else Console.WriteLine("No"); } // Driver code public static void Main() { string str = "abzzab"; checkevenOddPalindrome(str); } } // This code is contributed by sanjoy_62 JavaScript <script> // Javascript program implementation // of the approach // Function to check if the string // str is palindromic or not function isPalindrome(str) { // Pointers to iterate the // string from both ends var l = 0; var h = str.length - 1; while (h > l) { // If characters are found // to be distinct if (str.charAt(l++) != str.charAt(h--)) return false; } // Return true if the // string is palindromic return true; } // Function to generate string // from characters at odd indices function makeOddString(str) { var odd = ""; for(var i = 1; i < str.length; i += 2) { odd += str.charAt(i); } return odd; } // Function to generate string // from characters at even indices function makeevenString(str) { var even = ""; for(var i = 0; i < str.length; i += 2) { even += str.charAt(i); } return even; } // Functions to checks if string // is Even-Odd Palindrome or not function checkevenOddPalindrome(str) { // Generate odd indexed string var odd = makeOddString(str); // Generate even indexed string var even = makeevenString(str); // Check for Palindrome if (isPalindrome(odd) && isPalindrome(even)) document.write("Yes"); else document.write("No"); } // Driver code var str = "abzzab"; checkevenOddPalindrome(str); // This code is contributed by Khushboogoyal499 </script> Output: Yes Time Complexity: O(n) Auxiliary Space: O(n) Comment More infoAdvertise with us Next Article Check if a given string is Even-Odd Palindrome or not G grand_master Follow Improve Article Tags : Strings Competitive Programming Computer Science Fundamentals DSA palindrome +1 More Practice Tags : palindromeStrings Similar Reads Check given string is oddly palindrome or not Given string str, the task is to check if characters at the odd indexes of str form a palindrome string or not. If not then print "No" else print "Yes".Examples: Input: str = "osafdfgsg", N = 9 Output: Yes Explanation: Odd indexed characters are = { s, f, f, s } so it will make palindromic string, " 6 min read Check given string is oddly palindrome or not | Set 2 Given string str, the task is to check if characters at the odd indexes of str form a palindrome string or not. If not then print "No" else print "Yes". Examples: Input: str = "osafdfgsg", N = 9 Output: Yes Explanation: Odd indexed characters are = { s, f, f, s } so it will make palindromic string, 11 min read Check if any anagram of a string is palindrome or not Given an anagram string S of length N, the task is to check whether it can be made palindrome or not. Examples: Input : S = geeksforgeeks Output: NoExplanation: There is no palindrome anagram of given string Input: S = geeksgeeksOutput: YesExplanation: There are palindrome anagrams of given string. 8 min read Check if both halves of a string are Palindrome or not Given a string str, the task is to check whether the given string can be split into two halves, each of which is palindromic. If it is possible, print Yes. Otherwise, print No. Examples: Input: str = "naan" Output: No Explanation: Since both halves "na" and "an" are not palindrome. Input: momdad Out 5 min read Check if a given string is a rotation of a palindrome Given a string, check if it is a rotation of a palindrome. For example your function should return true for "aab" as it is a rotation of "aba". Examples: Input: str = "aaaad" Output: 1 // "aaaad" is a rotation of a palindrome "aadaa" Input: str = "abcd" Output: 0 // "abcd" is not a rotation of any p 15+ min read Check if it is possible to create a palindrome string from given N Given a number N. The task is to create an alphabetical string in lower case from that number and tell whether the string is palindrome or not. a = 0, b = 1â¦.. and so on. For eg: If the number is 61 the substring âgbâ will be printed till 7 (6+1) characters i.e. âgbgbgbgâ and check if palindrome or 7 min read Find if string is K-Palindrome or not | Set 2 Given a string, find out if the string is K-Palindrome or not. A K-palindrome string transforms into a palindrome on removing at most k characters from it.Examples: Input : String - abcdecba, k = 1 Output : Yes String can become palindrome by removing 1 character i.e. either d or e Input : String - 8 min read Find if string is K-Palindrome or not | Set 1 Given a string S, find out if the string is K-Palindrome or not. A K-palindrome string transforms into a palindrome on removing at most K characters from it.Examples : Input: S = "abcdecba", k = 1Output: YesExplanation: String can become palindrome by removing 1 character i.e. either d or e. Input: 15+ min read Check if a number with even number of digits is palindrome or not Given a number N containing an even number of digits. The task is to check whether that number is palindrome or not. Examples: Input: N = 123321 Output: Palindrome Input: 1234 Output: Not palindrome A Naive Approach is to traverse from the front and back of that number and stop where they do not mat 4 min read Like