Check if given string is a substring of string formed by repeated concatenation of z to a | Function checks if a given is valid or not and prints the output ; Boolean flag variable to mark if given is valid ; Traverse the given string ; If adjacent character differ by 1 ; If character ' a ' is followed by 4 ; Else flip the flag and break from the loop ; Output according to flag variable ; Driver Code ; Given string ; Function Call
def checkInfinite ( s ) : NEW_LINE INDENT flag = 1 NEW_LINE N = len ( s ) NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT if ( s [ i ] == chr ( ord ( s [ i + 1 ] ) + 1 ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT elif ( s [ i ] == ' a ' and s [ i + 1 ] == ' z ' ) : NEW_LINE INDENT continue NEW_LINE DEDENT else : NEW_LINE INDENT flag = 0 NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag == 0 ) : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = " ecbaz " NEW_LINE checkInfinite ( s ) NEW_LINE DEDENT