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
- Longest substring whose characters can be rearranged to form a Palindrome
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Check if characters of each word can be rearranged to form an Arithmetic Progression (AP)
- Find the count of sub-strings whose characters can be rearranged to form the given word
- Smallest prefix to be deleted such that remaining array can be rearranged to form a sorted array
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Check if the characters in a string form a Palindrome in O(1) extra space
- Check if a string contains uppercase, lowercase, special characters and numeric values
- Check if a string consists only of special characters
- Check if characters of one string can be swapped to form other
- Check if characters of a given string can be used to form any N equal strings
- Sentence Palindrome (Palindrome after removing spaces, dots, .. etc)
- Count all palindrome which is square of a palindrome
- Generate a string whose all K-size substrings can be concatenated to form the given string
- Number of positions where a letter can be inserted such that a string becomes palindrome
- Reverse a string without affecting special characters
- Split numeric, alphabetic and special symbols from a String
- Program to count vowels, consonant, digits and special characters in string.
- Count special palindromes in a String
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.