C++ || Easy and Understable
Connect with me LinkedIn  (:\n```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n\t//initializing frequency array to 0\n        long
**Connect with me** [LinkedIn  ](https://www.linkedin.com/in/aniket-kumar-singh1398/)**(:**\n```\nclass Solution {\npublic:\n    long long smallestNumber(long long num) {\n\t//initializing frequency array to 0\n        long long freq[10] = {0};\n     //checking if number is postive\n    bool is_pos = (num>0);\n   \n      //getting absolute value of the number\n    num = abs(num);\n   \n    //counting the frequency of each digit\n    while (num)\n    {\n        long long d = num % 10; \n        freq[d]++; \n        num = num / 10; \n    }\n    long long result = 0;\n      //if the number is positive then we make it smallest\n      if(is_pos)\n    {\n     //setting left most digit minimum and not 0\n      for (long long i = 1 ; i <= 9 ; i++)\n      {\n          if (freq[i])\n          {\n              result = i;\n              freq[i]--;\n              break;\n          }\n      }\n \n      //arranging in ascending order\n      for (long long i = 0 ; i <= 9 ; i++)\n          while (freq[i]--)\n              result = result * 10 + i;\n    }\n    else  //if the number is negative then it should be the largest\n    {\n      \n      for (long long i = 9 ; i >= 1 ; i--)\n      {\n         if (freq[i])\n         {\n            result = i;\n            freq[i]--;\n            break;\n         }\n      }\n       \n      //arranging all remaning in descending order\n      for (long long i = 9 ; i >=0 ; i--)\n         while (freq[i]--)\n            result = result * 10 + i;\n      //converting back the negative numbers\n      result = -result;\n    }\n    return result;\n        \n    }\n};
['C', 'C++']