VOOZH about

URL: https://www.geeksforgeeks.org/dsa/sudo-placement-palindrome-family/

⇱ Sudo Placement | Palindrome Family - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Sudo Placement | Palindrome Family

Last Updated : 7 Dec, 2022

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.

Examples

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: 

  1. Check if the given string is a Palindrome, if it is Print 'PARENT Palindrome'.
  2. If the first case is not true, check if both evenString and oddString are palindromes, if so then print 'TWIN Palindrome'
  3. 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'.
  4. If none of the above conditions satisfy, print 'ALIEN Palindrome'.

Below is the implementation of the above approach:


Output
ODD Palindrome
PARENT Palindrome
Alien Palindrome

Time Complexity: O(n), where n is the length of the given string.
Auxiliary Space: O(n), where n is the length of the given string.

Comment
Article Tags: