Given a string str, the task is to check if it can be rearranged to get a special palindromic string. If we can make it print YES else print NO.
A string is called special Palindrome that contains an uppercase and a lower case character of the same character in the palindrome position. Example- ABCcba is a special palindrome but ABCCBA is not a special palindrome.
Input: str = "ABCcba" Output: YES Input: str = "ABCCBA" Output: NO
Approach: Check if the occurrence of the uppercase letter of a character is same as the occurrence of lower case letter of the same character. And also there should be only one odd occurring character. We increase the frequency of each uppercase character by 1 and decrease the frequency of each lower case character by 1. After this, there should be either zero, 1 or -1 in the frequency array If anything else occurs then we directly say NO else print YES.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if characters of a given string can be rearranged to form a palindrome
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Check if the characters in a string form a Palindrome in O(1) extra space
- Find the count of sub-strings whose characters can be rearranged to form the given word
- Check if a given string is Even-Odd Palindrome or not
- Check if any anagram of a string is palindrome or not
- C Program to Check if a Given String is Palindrome
- Check whether the given string is Palindrome using Stack
- Check if a given string is a rotation of a palindrome
- Check given string is oddly palindrome or not
- Check given string is oddly palindrome or not | Set 2
- Check if both halves of a string are Palindrome or not
- Check if it is possible to create a palindrome string from given N
- Check if a string is palindrome in C using pointers
- Check if there exists any sub-sequence in a string which is not palindrome
- Java program to check whether a string is a Palindrome
- Given two strings check which string makes a palindrome first
- Recursive function to check if a string is palindrome
- Python program to check if a string is palindrome or not
- Python program to check if given string is vowel Palindrome
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.