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 <= 10^{7}
0 <= A_{i }<= 9

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3

class Solution:
    def MaxNumber(self, arr, n):
        #code here.
    



Solutions:
class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr.reverse()
		a = list(map(str, arr))
		k = ''.join(a)
		return k


class Solution:

	def MaxNumber(self, arr, n):
		a = ''
		arr.sort()
		arr = arr[::-1]
		for i in arr:
			a += str(i)
		return int(a)


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		a = []
		for i in range(0, n):
			a.append(arr[i])
		a.reverse()
		k = int(''.join(map(str, a)))
		return k


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		s = ''
		for i in range(n):
			s += str(arr[i])
		return s


class Solution:

	def MaxNumber(self, arr, n):
		aux = []
		for i in range(10):
			aux.append(0)
		for i in range(n):
			aux[arr[i]] = aux[arr[i]] + 1
		i = 9
		result = ''
		while i >= 0:
			if aux[i] > 0:
				for j in range(aux[i]):
					result = result + str(i)
			i = i - 1
		return result


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		st = ''
		for i in arr:
			st = st + str(i)
		return st


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr = arr[::-1]
		s = ''
		for i in range(n):
			s = s + str(arr[i])
		return s


class Solution:

	def MaxNumber(self, arr, n):
		count = [0] * 10
		for i in range(n):
			count[arr[i]] += 1
		result = []
		for i in range(9, -1, -1):
			result.extend([str(i)] * count[i])
		num = int(''.join(result))
		return num


class Solution:

	def MaxNumber(self, arr, n):
		arr = sorted(arr, reverse=True)
		ans = ''
		for i in range(n):
			ans += str(arr[i])
		return ans


class Solution:

	def MaxNumber(self, arr, n):
		arr = map(str, arr)
		a = sorted(arr)
		v = a[::-1]
		s = ''
		for i in v:
			s = s + i
		return s


class Solution:

	def MaxNumber(self, arr, n):
		l = ''
		arr.sort(reverse=True)
		for i in range(len(arr)):
			l += str(arr[i])
		return l


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		m = arr[::-1]
		st = map(str, m)
		s = ''
		for i in st:
			s += i
		return s


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr[:] = arr[::-1]
		s1 = ''
		for i in arr:
			s1 += str(i)
		return s1


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		str1 = ''
		for i in range(n - 1, -1, -1):
			str1 += str(arr[i])
			continue
		return str1


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		s = ''
		for i in arr:
			s += str(i)
		s = s[::-1]
		k = int(s)
		return k


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr = arr[::-1]
		ans = 0
		str1 = ''.join((str(i) for i in arr))
		ans = int(str1)
		return ans


class Solution:

	def MaxNumber(self, arr, n):
		arr = sorted(arr, reverse=True)
		stri = ''
		for i in arr:
			stri += str(i)
		return stri


class Solution:

	def MaxNumber(self, arr, n):
		times = {i: 0 for i in range(9, -1, -1)}
		for num in arr:
			times[num] += 1
		s = ''
		for num in range(9, -1, -1):
			s += str(num) * times[num]
		return s


class Solution:

	def MaxNumber(self, arr, n):
		return ''.join(map(str, sorted(arr, reverse=True)))


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		return ''.join([str(x) for x in arr])


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr = [x for x in reversed(arr)]
		arr2 = ''
		for x in arr:
			arr2 += str(x)
		return int(str(arr2))


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr.reverse()
		string_max = ''.join((str(i) for i in arr))
		return int(string_max)


class Solution:

	def MaxNumber(self, arr, n):
		count = [0] * 10
		for i in arr:
			count[i] += 1
		j = 0
		for i in range(9, -1, -1):
			while count[i] > 0:
				arr[j] = i
				j += 1
				count[i] -= 1
		s = ''
		for i in arr:
			s += str(i)
		return s


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		res = ''
		for i in range(n - 1, -1, -1):
			res += str(arr[i])
		return int(res)


class Solution:

	def MaxNumber(self, arr, n):
		s = ''
		arr = sorted(arr)
		for i in reversed(range(n)):
			s = s + str(arr[i])
		return s


class Solution:

	def MaxNumber(self, arr, n):
		w = ''
		arr.sort(reverse=True)
		for i in range(0, len(arr)):
			w = w + str(arr[i])
		return int(w)


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		op = ''.join(map(str, arr))
		return op


class Solution:

	def MaxNumber(self, arr, n):
		count = [0] * 10
		string = ''
		for item in arr:
			count[item] += 1
		for i in range(9, -1, -1):
			instances = count[i]
			while instances:
				string += str(i)
				instances -= 1
		return int(string)


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		string = ''
		for item in arr:
			string += str(item)
		return int(string)


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		output = ''
		for number in arr[::-1]:
			output += str(number)
		return output


class Solution:

	def MaxNumber(self, arr, n):
		p = ''
		arr.sort()
		for i in range(n - 1, -1, -1):
			z = str(arr[i])
			p += z
		q = int(p)
		return q


class Solution:

	def MaxNumber(self, arr, n):
		stri = ''
		map = {9: 0, 8: 0, 7: 0, 6: 0, 5: 0, 4: 0, 3: 0, 2: 0, 1: 0, 0: 0}
		for i in range(n):
			if arr[i] in map:
				map[arr[i]] += 1
		for i in map:
			if map[i] != 0:
				while map[i] != 0:
					stri += str(i)
					map[i] -= 1
		return stri[::-1]


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr.reverse()
		st = ''
		for i in range(n):
			st = st + str(arr[i])
		return int(st)


class Solution:

	def MaxNumber(self, arr, n):
		x = sorted(arr, reverse=True)
		s = ''
		for i in x:
			s = s + str(i)
		return s


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		l = [str(x) for x in arr]
		ans = ''.join(l)
		return int(ans)


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		return int(''.join([str(val) for val in arr]))


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		arr.reverse()
		b = ''.join([str(elem) for elem in arr])
		return b


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		a = ''
		for ele in arr:
			a = a + str(ele)
		return a


class Solution:

	def MaxNumber(self, arr, n):
		count = [0] * 10
		for num in arr:
			count[num] += 1
		res = ''
		sum = n
		for i in range(9, -1, -1):
			while count[i] != 0:
				res += str(i)
				count[i] -= 1
		return res


class Solution:

	def MaxNumber(self, arr, n):
		a = [0] * 10
		for j in arr:
			a[j] = a[j] + 1
		r = ''
		for j in range(9, -1, -1):
			for k in range(a[j]):
				r += str(j)
		return r


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		ans = ''.join((str(num) for num in arr))
		return ans


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		s = ''
		for z in arr:
			s += str(z)
		return s


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		number = ''.join((str(i) for i in arr))
		return number


class Solution:

	def MaxNumber(self, arr, n):
		li = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
		for i in range(n):
			li[arr[i]] = li[arr[i]] + 1
		number = ''
		for i in range(9, -1, -1):
			if li[i] != 0:
				number = number + str(str(i) * li[i])
		return int(number)


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		s = arr[::-1]
		return ''.join(map(str, s))


class Solution:

	def MaxNumber(self, arr, n):
		a = sorted(arr)
		a = a[::-1]
		b = []
		for i in a:
			p = str(i)
			b.append(p)
		c = ''.join(b)
		return int(c)


class Solution:

	def MaxNumber(self, arr, n):
		arr = sorted(arr, reverse=True)
		i = 0
		st = ''
		while i < len(arr):
			st += str(arr[i])
			i += 1
		return st


class Solution:

	def MaxNumber(self, arr, n):
		c = ''
		arr.sort()
		for j in reversed(range(n)):
			c = c + str(arr[j])
		return c


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort()
		x = arr[::-1]
		y = ''
		for i in x:
			y = y + str(i)
		return y


class Solution:

	def MaxNumber(self, arr, n):
		arr.sort(reverse=True)
		l = list(map(str, arr))
		s = ''.join(l)
		return s