Check if a string follows a ^ nb ^ n pattern or not | Python3 code to check a ^ nb ^ n pattern ; if length of str is odd return No ; check first half is ' a ' and other half is full of 'b ; Driver code ; Function call
def isanbn ( str ) : NEW_LINE INDENT n = len ( str ) NEW_LINE if n & 1 : NEW_LINE INDENT return " No " NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT for i in range ( int ( n / 2 ) ) : NEW_LINE INDENT if str [ i ] != ' a ' or str [ n - i - 1 ] != ' b ' : NEW_LINE return " No " NEW_LINE DEDENT return " Yes " NEW_LINE DEDENT input_str = " ab " NEW_LINE print ( isanbn ( input_str ) ) NEW_LINE