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
def printMiddleString ( S , T , N ) : NEW_LINE INDENT a1 = [ 0 ] * ( N + 1 ) ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT a1 [ i + 1 ] = ord ( S [ i ] ) - ord ( " a " ) + ord ( T [ i ] ) - ord ( " a " ) ; NEW_LINE DEDENT for i in range ( N , 1 , - 1 ) : NEW_LINE INDENT a1 [ i - 1 ] += a1 [ i ] // 26 ; NEW_LINE a1 [ i ] %= 26 ; NEW_LINE DEDENT for i in range ( N + 1 ) : NEW_LINE INDENT if ( a1 [ i ] & 1 ) : NEW_LINE if ( i + 1 <= N ) : NEW_LINE INDENT a1 [ i + 1 ] += 26 ; NEW_LINE DEDENT a1 [ i ] = a1 [ i ] // 2 ; NEW_LINE DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT print ( chr ( a1 [ i ] + ord ( " a " ) ) , end = " " ) ; NEW_LINE DEDENT return 0 ; NEW_LINE DEDENT N = 5 ; NEW_LINE S = " afogk " ; NEW_LINE T = " asdji " ; NEW_LINE printMiddleString ( S , T , N ) ; NEW_LINE