Given a string of lowercase characters, the task is to detect the family of string, where family of string is described as follows.
- ODD Palindrome : String with characters at odd index (1-based indexing) forming Palindrome.
- EVEN Palindrome : String with characters at even index (1-based indexing) forming Palindrome.
- TWIN Palindrome : String with both of the above properties.
- PARENT Palindrome : If the string is itself a Palindrome.
Input : geeksforskeeg
Output : ODD Palindrome
Explanation: The string with characters at odd indices(following 1-based indexing) is ‘gesoseg‘, which is a palindrome, while the string formed by characters at even indices does not form a palindrome. Thus the given string is of ‘ODD‘ Family.
Input : aibohobia
Output : PARENT Palindrome
Explanation: The string itself is a palindrome, thus falls under PARENT Family.
Approach: Define 2 empty strings, oddString and evenString.
- Append all the characters at even indices in the evenString.
- Append all the characters at odd indices in the oddString.
Now, check for the following cases:
- Check if the given string is a Palindrome, if it is Print ‘PARENT Palindrome’.
- If the first case is not true, check if both evenString and oddString are palindromes, if so then print ‘TWIN Palindrome’
- If the second case doesn’t hold true, then if evenString is a Palindrome, print ‘EVEN Palindrome’, else if oddString is a Palindrome print ‘ODD Palindrome’.
- If none of the above conditions satisfy, print ‘ALIEN Palindrome’.
Below is the implementation of above approach:
ODD Palindrome PARENT Palindrome Alien Palindrome
- Sudo Placement | Placement Tour
- Sudo Placement[1.4] | K Sum
- Sudo Placement[1.5] | Wolfish
- Sudo Placement[1.5] | Partition
- Sudo Placement[1.4] | BST Traversal
- Sudo Placement[1.4] | Jumping the Subtree
- Sudo Placement | Beautiful Pairs
- Sudo Placement | Special Subsequences
- Sudo Placement[1.5] | Second Smallest in Range
- Sudo Placement[1.3] | Final Destination
- Sudo Placement[1.3] | Stack Design
- Sudo Placement[1.3] | Playing with Stacks
- Sudo Placement | Range Queries
- Sudo Placement 2 | Matrix Series
- Sudo Placement[1.7] | Greatest Digital Root
This article is contributed by Team GeeksforGeeks. 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.