Java Solution Using Frequency Array
```\nclass Solution {\n    public long smallestNumber(long num) {\n        if(num >= -9 && num<= 9) {return num;}\n      \n        int digits[] = new int [10];\
```\nclass Solution {\n    public long smallestNumber(long num) {\n        if(num >= -9 && num<= 9) {return num;}\n      \n        int digits[] = new int [10];\n        long numCopy = Math.abs(num);\n        long ans = 0;\n      \n        while(numCopy > 0) {\n          int index = (int)(numCopy % 10);\n          digits[index] = digits[index]+1;\n          numCopy = numCopy/10;\n        }\n      \n        if(num > 0) {\n          for(int i = 1; i < 10; i++) {\n            while(digits[i] > 0) {\n              ans = ans*10 + i;\n              while(digits[0] > 0) {\n                ans = ans*10;\n                digits[0]--;\n              }\n             digits[i]--;\n            }\n          }\n        }\n      \n        else {\n          for(int i = 9; i >= 0; i--) {\n             while(digits[i] > 0) {\n               ans = ans*10 + i;\n               digits[i]--;\n             }\n          }\n          ans = -ans;\n        }\n        return ans;\n    }\n}
[]