Given two arrays of digits A[],B[] replace digits in A with B to form largest number in A


  • 1
    J

    Given two arrays of digits say A[] and B[], replace the digits in A with digits in B such that when you consider A as a number it is the largest possible. Digits in B cant be used more than once.


  • 1

    One solution I can think of is first sort B[ ] in descending order, then try to use B[0] to replace A[0], if B[0] is greater than A[0], replace it, otherwise compare B[0] and A[1] ... till we go through A or B is all used.


  • 0
    Y
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.