Intutive | Brute force | Hash map
\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        string s = to_string(num);\n       if(num ==0)return 0;\n        string w=""
```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n        string s = to_string(num);\n       if(num ==0)return 0;\n        string w="";\n       \n      //for -ve\n        if(s[0]==\'-\'){\n            map<char,int,greater<int>>mp; //descending map (greater -ve  smaller the number)\n            for(auto i : s){\n                mp[i]++;\n            }\n             for(auto i : mp){\n               while(i.second){\n                   w+=i.first;\n                   i.second--;\n               \n               }\n           }\n            long long n = stoll(w);\n            return -1*n;\n        }\n        //---------------------------------------------------------------------------\n\t\t//For +ve\n        else{\n            map<char,int>mp;// ascending map\n            \n               for(auto i : s){\n                mp[i]++;\n            }\n                \n                \n           for(auto i : mp){\n               if(i.first != \'0\'){\n                while(i.second){\n                  w+=i.first;\n                  i.second--;\n\t\t\t\t  \n\t\t\t\t  //handling case of \'0\' when positive number\n                  if(mp.find(\'0\')!=mp.end()){\n                    while(mp[\'0\']){\n                        w+=\'0\';\n                        mp[\'0\']--;\n                    }\n              }\n             \n           }\n           }\n           }\n    \n \n            \n          long long n = stoll(w);\n            return n;\n        }  \n    }\n    \n};\n```
[]