Find the string present at the middle of a lexicographically increasing sequence of strings from S to T | Function to print the string at the middle of lexicographically increasing sequence of strings from S to T ; Stores the base 26 digits after addition ; Iterete from right to left and add carry to next position ; Reduce the number to find the middle string by dividing each position by 2 ; If current value is odd , carry 26 to the next index value ; Driver Code
function printMiddleString ( S , T , N ) { let a1 = new Array ( N + 1 ) ; for ( let i = 0 ; i < N ; i ++ ) { a1 [ i + 1 ] = S [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) + T [ i ] . charCodeAt ( 0 ) - " " . charCodeAt ( 0 ) ; } for ( let i = N ; i >= 1 ; i -- ) { a1 [ i - 1 ] += a1 [ i ] / 26 ; a1 [ i ] %= 26 ; } for ( let i = 0 ; i <= N ; i ++ ) { if ( a1 [ i ] & 1 ) { if ( i + 1 <= N ) { a1 [ i + 1 ] += 26 ; } } a1 [ i ] = Math . floor ( a1 [ i ] / 2 ) ; } for ( let i = 1 ; i <= N ; i ++ ) { document . write ( String . fromCharCode ( a1 [ i ] + " " . charCodeAt ( 0 ) ) ) ; } return 0 ; } let N = 5 ; let S = " " ; let T = " " ; printMiddleString ( S , T , N ) ;