Find the largest number that can be formed with the given digits | Function to generate largest possible number with given digits ; Declare a hash array of size 10 and initialize all the elements to zero ; store the number of occurrences of the digits in the given array into the hash table ; Traverse the hash in descending order to print the required number ; Print the number of times a digits occurs ; Driver code
function findMaxNum ( arr , n ) { var hash = Array ( 10 ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { hash [ arr [ i ] ] ++ ; } for ( var i = 9 ; i >= 0 ; i -- ) { for ( var j = 0 ; j < hash [ i ] ; j ++ ) document . write ( i ) ; } } var arr = [ 1 , 2 , 3 , 4 , 5 , 0 ] ; var n = arr . length ; findMaxNum ( arr , n ) ;