Form largest number from digits
Basic Accuracy: 27.44% Submissions: 62 Points: 1

Given an array of numbers form 0 to 9 of size N. Your task is to rearrange elements of the array such that after combining all the elements of the array number formed is maximum.

 

Example 1:

Input:
N = 5
A[] = {9, 0, 1, 3, 0}
Output:
93100
Explanation:
Largest number is 93100 which
can be formed from array digits.

 

Example 2:

Input:
N = 3
A[] = {1, 2, 3}
Output:
321

 

Your Task:  
You don't need to read input or print anything. Your task is to complete the function MaxNumber() which takes the array A[] and its size N as inputs and returns a single line a string denoting the largest number that can be achieved by rearranging the elements of the array.


Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)


Constraints:
1 <= N <= 107

0 <= Ai <= 9

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.