[GE][First Method]Find smallest permutation of given number
Given a long integer, return the smallest(magnitude) integer permutation of that number.
Examples:
Input : 5468001 Output : 1004568 Input : 5341 Output : 1345
Approach : As number is long, store the number as string, sort the string, if there is no leading zero, return this string, if there is any leading zero, swap first element of string with first non-zero element of string, and return the string.
Below is the implementation of above approach :
Output:
1004568
Output:
1004568
Output:
1004568
Comments
Post a Comment