[GE][First Method]Find smallest permutation of given number
Smallest number by rearranging digits of a given number
Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number.
Examples:
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.
Output:
100577
Output:
100577
Comments
Post a Comment