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:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course