Easy Solution | with comment
\n//The Idea is to  form a number from sorted list of numbers(Integer/Long) \n// if the given number is neative form  maximum else minimum number\n\n\tclass Sol
\n//The Idea is to  form a number from sorted list of numbers(Integer/Long) \n// if the given number is neative form  maximum else minimum number\n\n\tclass Solution {\n\t\tpublic long smallestNumber(long num) {\n\t\t\tboolean flag = false;\n\t\t\tList<Long>list = new ArrayList<>();\n\t\t\t// flag the neagtive(for further reference ) and make the number positve\n\t\t\tif(num < 0){\n\t\t\t\tflag = true;\n\t\t\t\tnum = num * -1;\n\t\t\t}\n\n\t// storing the number in arraylist\n\t\t\twhile(num > 0){\n\t\t\t\tlong rem = num % 10;\n\t\t\t\tlist.add(rem);\n\t\t\t\tnum = num /10;\n\t\t\t}\n\t\t\t\n\t\t\t//sort the list as per flag value\n\t\t\tif(flag){\n\t\t\t\tCollections.sort(list, Collections.reverseOrder());\n\t\t\t}else{\n\t\t\t\tCollections.sort(list);\n\t\t\t}\n\n\t// if there will be multiple 0s in front \n\t\t\tint cnt = -1;\n\t\t\tfor(int i=0;i<list.size();i++){\n\t\t\t\tif(list.get(i) == 0) cnt++;\n\t\t\t\telse break;\n\t\t\t}\n\t\t\tlong sm = -1l;\n\t\t\tif(cnt != -1){\n\t\t\t\tcnt = cnt+1;\n\t\t\t\tif(list.size() > cnt){\n\t\t\t\t\tsm = list.get(cnt);\n\t\t\t\t\tlist.remove(cnt);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlong res = 0;\n\t\t\tint itr = 0;\n\t\t\tif(sm != -1) res = sm;\n\t// Form the number\n\t\t\twhile(itr < list.size()){\n\t\t\t\tlong mul = list.get(itr);\n\t\t\t\tres = res  * 10 + mul;\n\t\t\t\titr++;\n\t\t\t}\n\t// if given number was negative, make the result neagtive\n\t\t\tif(flag) res = res * -1;\n\n\t\t\treturn res;\n\n\t\t\t}\n\t\t}\n\t}
['Java']