|| Fundamental Approach || C++ || String Manip ||
Code\n\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        string n = to_string(num);\n        string min = "";\n        string max = "";\n
# Code\n```\nclass Solution {\npublic:\n    int minMaxDifference(int num) {\n        string n = to_string(num);\n        string min = "";\n        string max = "";\n        int i=0;\n        while(i < n.size() and n[i] == \'9\')  {\n            i++;\n        }\n        if(i < n.size()) {\n            char remax = n[i];\n            for(auto val: n) {\n                if(val == remax)\n                    max += \'9\';\n                else\n                    max += val;\n            }\n        }\n        else\n            max = n;\n        i=0;\n        while(i < n.size() and n[i] == \'0\') \n            i++;\n        if(i < n.size()) {\n            char remin = n[i];\n            for(auto val: n) {\n                if(val == remin)\n                    min += \'0\';\n                else\n                    min += val;\n            }\n        }\n        else\n            min = n;\n        return stoi(max)-stoi(min);\n    }\n};\n// Please consider upvoting if the solution helped! Thank you :)\n// By VasudevaK (V Deva K)\n```
['C++']