text: Check if given string is a substring of string formed by repeated concatenation of z to a | C # program for the above approach ; 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 ; Driver code ; Given string ; Function call
code: using System ; class GFG { public static void checkInfinite ( String s ) { bool flag = true ; int N = s . Length ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( s [ i ] == ( char ) ( ( int ) ( s [ i + 1 ] ) + 1 ) ) { continue ; } else if ( s [ i ] == ' a ' && s [ i + 1 ] == ' z ' ) { continue ; } else { flag = false ; break ; } } if ( ! flag ) Console . Write ( " NO " ) ; else Console . Write ( " YES " ) ; } public static void Main ( String [ ] args ) { String s = " ecbaz " ; checkInfinite ( s ) ; } }