Check given string is oddly palindrome or not | Set 2 | Functions checks if characters at odd index of the string forms palindrome or not ; Initialise two pointers ; Iterate till left <= right ; If there is a mismatch occurs then return false ; Increment and decrement the left and right pointer by 2 ; Driver Code ; Given string ; Function call
def isOddStringPalindrome ( Str , n ) : NEW_LINE INDENT left , right = 0 , 0 NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT left = 1 NEW_LINE right = n - 1 NEW_LINE DEDENT else : NEW_LINE INDENT left = 1 NEW_LINE right = n - 2 NEW_LINE DEDENT while ( left < n and right >= 0 and left < right ) : NEW_LINE INDENT if ( Str [ left ] != Str [ right ] ) : NEW_LINE INDENT return False NEW_LINE DEDENT left += 2 NEW_LINE right -= 2 NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 10 NEW_LINE Str = " aeafacafae " NEW_LINE if ( isOddStringPalindrome ( Str , n ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT