text: Maximize the value of A by replacing some of its digits with digits of B | C # implementation of the approach ; Function to return the maximized value of A ; Sort digits in ascending order ; j points to largest digit in B ; If all the digits of b have been used ; Current digit has been used ; Return the maximized value ; Driver code
code: using System ; class GFG { static String maxValue ( char [ ] a , char [ ] b ) { Array . Sort ( b ) ; int n = a . Length ; int m = b . Length ; int j = m - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( j < 0 ) break ; if ( b [ j ] > a [ i ] ) { a [ i ] = b [ j ] ; j -- ; } } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { String a = "1234" ; String b = "4321" ; Console . Write ( maxValue ( a . ToCharArray ( ) , b . ToCharArray ( ) ) ) ; } }