Minimum number to be added to all digits of X to make X > Y | Function to check if X is lexicographically larger Y ; It is lexicographically larger ; Utility function to check minimum value of d ; If X is already larger do not need to add anything ; Adding d to all elements of X ; If X is larger now print d ; else print d + 1 ; Driver Code ; Taking the numbers as sequences
def IsLarger ( X , Y , n ) : NEW_LINE INDENT for i in range ( n ) : NEW_LINE INDENT if ( X [ i ] < Y [ i ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT def solve ( X , Y , n ) : NEW_LINE INDENT ans = 0 ; NEW_LINE if ( IsLarger ( X , Y , n ) ) : NEW_LINE INDENT ans = 0 ; NEW_LINE DEDENT else : NEW_LINE INDENT d = Y [ 0 ] - X [ 0 ] ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT X [ i ] += d ; NEW_LINE DEDENT if ( IsLarger ( X , Y , n ) ) : NEW_LINE INDENT ans = d ; NEW_LINE DEDENT else : NEW_LINE INDENT ans = d + 1 ; NEW_LINE DEDENT DEDENT return ans ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT X = [ 2 , 3 , 6 , 9 ] ; NEW_LINE Y = [ 3 , 4 , 8 , 1 ] ; NEW_LINE n = len ( X ) ; NEW_LINE print ( solve ( X , Y , n ) ) ; NEW_LINE DEDENT