See the original problem on HackerRank.
MegaBytus is a young and promising wizard who loves programming and computers. The master GigaBytus gave him a task: crafting a spell to rearrange the digits of a number such that the number obtained is the smallest possible.
MegaBytus needs your help to find a way to verify that his spell works. Then you have to write a program that, given an integral number, will find the smallest number obtained by rearranging its digits.
Can you help him?
The number N
N has at least 6 digits and at most 19.
The new number, on a single line
The resulting number is produced by putting the smallest non-zero number first and then all the others, in increasing order (including duplicates).
Here is a a C++ solution based on frequency table:
Alternatives involve sorting with special comparison functions, left as exercises.