Minimum number to be added to all digits of X to make X > Y | C # program to find 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
using System ; class GFG { static bool IsLarger ( int [ ] X , int [ ] Y , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( X [ i ] < Y [ i ] ) { return false ; } } return true ; } static int solve ( int [ ] X , int [ ] Y , int n ) { int ans = 0 ; if ( IsLarger ( X , Y , n ) ) ans = 0 ; else { int d = Y [ 0 ] - X [ 0 ] ; for ( int i = 0 ; i < n ; i ++ ) X [ i ] += d ; if ( IsLarger ( X , Y , n ) ) ans = d ; else { ans = d + 1 ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] X = { 2 , 3 , 6 , 9 } ; int [ ] Y = { 3 , 4 , 8 , 1 } ; int n = X . Length ; Console . WriteLine ( solve ( X , Y , n ) ) ; } }