Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number.
Input: n = 846903 Output: 304689 Input: n = 55010 Output: 10055
Steps to find the smallest number.
- Count the frequency of each digit in the number.
- Place the smallest digit (except 0) at the left most of required number.
and decrement the frequency of that digit by 1.
- Place all remaining digits in ascending order from left to right.
This solution is based on counting sort.
Another Approach:Find smallest permutation of given number
This article is contributed by Ajay Kumar Agrahari(aJy aGr). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Largest number not greater than N which can become prime after rearranging its digits
- Find smallest number with given number of digits and sum of digits
- Find the smallest number whose digits multiply to a given number n
- Immediate smallest number after re-arranging the digits of a given number
- Smallest number with given sum of digits and sum of square of digits
- Get the kth smallest number using the digits of the given number
- Smallest Even number with N digits
- Smallest even digits number not less than N
- Smallest odd digits number not less than N
- Smallest odd number with N digits
- Smallest number with sum of digits as N and divisible by 10^N
- Smallest number with at least n digits in factorial
- Smallest multiple of a given number made of digits 0 and 9 only
- Smallest number k such that the product of digits of k is equal to n
- Find the smallest positive number which can not be represented by given digits