C++ Using Map
Here, the idea is to the store the digits of the number along with their frequencies in a hashmap and then build the smallest possible number using those digits
Here, the idea is to the store the digits of the number along with their frequencies in a hashmap and then build the smallest possible number using those digits in increasing order(except for leading 0).\n```\n    long long smallestNumber(long long num) {\n        if(num==0)\n            return 0;\n        long long x=num, min=0;\n        int rem=0;\n        map<int,int> hash;\n        while(x!=0)\n        {\n            rem=x%10;\n            x/=10;\n            hash[rem]++;\n        }\n        map<int,int>:: iterator it=hash.begin();\n        while(it->first==0)\n            it++;\n        min=min*10+(it->first);\n        it->second--;\n        it=hash.begin();\n        while(it!=hash.end())\n        {\n            if(it->second>0)\n            {\n                min=min*10+(it->first);\n                it->second--;\n            }\n            else\n                it++;\n        }\n        return min;\n    }\n```
['Math', 'C']