Accenture Coding Question | Array Permutation | CodeWindow

Array Permutation

The function accepts an integer array ‘arr’ of length ‘size’ as the argument. Implement the function to find and return the maximum number that can be formed by any permutation or arrangement of the digits obtained from all the numbers present in the array. You have to return the number formed as a string.
Note: You may need to rearrange the digits of the numbers to form the maximum number.

Example:
Input: 34 79 58 64

Output: 98765443
Explanation:
All digits from all the numbers of the array are 3,4,7,9,5,8,6,4. Maximum number obtained after rearranging all these digit gives 98765443.

Sample input:
21 90 23

Sample Output:
932210

Solution in Python 3:

#https://codewindow.in
#join our telegram channel

from itertools import permutations
s=input()
s=list(s)
a=[]
#print(s)
for i in s:
    if i!=' ':
        a.append(i)
l=len(a)

b = permutations(a,l)
y = [''.join(i) for i in b]
#print(y)

y=sorted(y)
ans=y[-1:]
print(''.join(ans))

# Telegram @codewindow

Output:

21 90 23
932210
34 79 58 64
98765443
Recent Posts

Leave a Comment

Your email address will not be published. Required fields are marked *