Check if given string is a substring of string formed by repeated concatenation of z to a | Function checks if a given string is valid or not and prints the output ; Boolean flag variable to mark if given string 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 ; Given string ; Function Call
function checkInfinite ( s ) { var flag = 1 ; var N = s . length ; for ( var i = 0 ; i < N - 1 ; i ++ ) { if ( s [ i ] == String . fromCharCode ( ( s [ i + 1 ] . charCodeAt ( 0 ) ) + 1 ) ) { continue ; } else if ( s [ i ] == ' ' && s [ i + 1 ] == ' ' ) { continue ; } else { flag = 0 ; break ; } } if ( flag == 0 ) document . write ( " " ) ; else document . write ( " " ) ; } var s = " " ; checkInfinite ( s ) ;