Python program to sort digits of a number in ascending order
Given an integer N, the task is to sort the digits in ascending order. Print the new number obtained after excluding leading zeroes.
Input: N = 193202042
Sorting all digits of the given number generates 001222349.
Final number obtained after removal of leading 0s is 1222349.
Input: N = 78291342023
Approach: Follow the steps below to solve the problem:
- Convert the given integer to its equivalent string
- Sort the characters of the string using join() and sorted().
- Convert string to integer using type casting
- Print the integer obtained.
Below is the implementation of the above approach:
Time Complexity: O(N*log(N))
Auxiliary Space: O(N)