Python program to print sorted number formed by merging all elements in array
Given an array arr, the task is to combine all the elements in the array sequentially and sort the digits of this number in ascending order.
Note: Ignore leading zeros.
Input: arr =[7, 845, 69, 60]
Explanation: The number formed by combining all the elements is “78456960” after sorting the digits we get 4566789
Input: arr =[8, 5603, 109, 53209]
Explanation: The number formed by combining all the elements is “8560310953209” after sorting the digits we get “1233556899”
- Convert each element of the list to a string using map() function.
- Join the list using join() function.
- Sort the string using join() and sorted()
- Convert string to an integer using type casting
- Return the result
Below is the implementation of the above approach: