Greedy algorithm (Find out maximum number)
Help me please problem :- I want to make max number out of digit Solution 1:- sort the list in descending order But the problem is if there are 2 digit 2 21 suppose So,ans is 212 But correct ans should be 221 Solution 2:- make permutations of given no and then find max but it is exceeding time limit of 5 sec Pls provide a approach . Example:- Input 9 4 6 1 9 Output:-99641 In this case normal sorting can be done and then reverse --------------------------------------------------- Example 2:- Input:-21 2 Output :- 221 If I used above algorithm ie sort >>2 21 Reverse>>212 The answer is wrong Output :- 221. ------------------------------------------------------------------------ Input:- 23 213 Output:-23213 https://code.sololearn.com/cOVy49jjv3rW/?ref=app https://code.sololearn.com/cYMyc7oxa12A/?ref=app