Find a string in lexicographic order which is in between given two strings | C # program to find the string in lexicographic order which is in between given two strings ; Function to find the lexicographically next string ; Iterate from last character ; If not ' z ' , increase by one ; if ' z ' , change it to ' a ' ; Driver Code ; If not equal , print the resultant string
using System ; public class GFG { static String lexNext ( String str , int n ) { char [ ] s = str . ToCharArray ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != ' z ' ) { s [ i ] ++ ; return new String ( s ) ; } s [ i ] = ' a ' ; } return null ; } static public void Main ( ) { String S = " abcdeg " , T = " abcfgh " ; int n = S . Length ; String res = lexNext ( S , n ) ; if ( res != T ) { Console . Write ( res ) ; } else { Console . Write ( " - 1" ) ; } } }