Check given string is oddly palindrome or not | Set 2 | Function to check if string formed by odd indices is palindromic or not ; Check if length of OddString odd , to consider edge case ; Push odd index character of first half of str in stack ; Middle element of odd length palindromic string is not compared ; If stack is empty then return true ; Driver code ; Given string
def isOddStringPalindrome ( str , n ) : NEW_LINE INDENT oddStringSize = n // 2 ; NEW_LINE lengthOdd = True if ( oddStringSize % 2 == 1 ) else False NEW_LINE s = [ ] NEW_LINE i = 1 NEW_LINE c = 0 NEW_LINE while ( i < n and c < oddStringSize // 2 ) : NEW_LINE INDENT s . append ( str [ i ] ) NEW_LINE i += 2 NEW_LINE c += 1 NEW_LINE DEDENT if ( lengthOdd ) : NEW_LINE INDENT i = i + 2 NEW_LINE DEDENT while ( i < n and len ( s ) > 0 ) : NEW_LINE INDENT if ( s [ len ( s ) - 1 ] == str [ i ] ) : NEW_LINE INDENT s . pop ( ) NEW_LINE DEDENT else : NEW_LINE INDENT break NEW_LINE DEDENT i = i + 2 NEW_LINE DEDENT if ( len ( s ) == 0 ) : NEW_LINE INDENT return True NEW_LINE DEDENT return False ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 10 NEW_LINE s = " aeafacafae " NEW_LINE if ( isOddStringPalindrome ( s , N ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT