Find a 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
function lexNext ( s , n ) { for ( let i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != ' ' ) { let code = s . charCodeAt ( i ) + 1 ; let str = String . fromCharCode ( code ) ; return s . substr ( 0 , i ) + str + s . substr ( i + 1 ) ; } s [ i ] = ' ' ; } } let S = " " ; let T = " " ; let n = S . length ; let res = lexNext ( S , n ) ; if ( res != T ) document . write ( res , ' ' ) ; else document . write ( " " ) ;