✅C++ | ✅Intuitive Approach
Intuition\nMaximum number of any digit starts with 9 like 9, 99, 999 etc.\nMinimum number of any digit start with 0 like 0, 01, 010, 0100 etc. (Considering cond
# Intuition\nMaximum number of any digit starts with 9 like 9, 99, 999 etc.\nMinimum number of any digit start with 0 like 0, 01, 010, 0100 etc. (Considering condition given in the problem- "The resulting number after remapping can contain leading zeroes.")\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution \n{\npublic:\n    int minMaxDifference(int num) \n    {\n        string s = to_string(num);\n        string t = s;\n        int n=s.size();\n        char digit;\n        \n        //making num maximum by replacing first non-nine digit with 9 \n        for(int i=0; i<n; i++)\n        {\n            if(s[i] != \'9\') \n            {\n                digit = s[i];\n                s[i] = \'9\';\n                while(i<n) //replacing all position of that digit with 9\n                {\n                    if(s[i]==digit)\n                        s[i]=\'9\';\n                    i++;\n                }\n                break;\n            }\n        }\n        int maxi = stoi(s);\n        \n        //making num minimum by replacing first non-zero digit with 0\n        for(int i=0; i<n; i++)\n        {\n            if(t[i] != \'0\')\n            {\n                digit = t[i];\n                t[i] = \'0\';\n                while(i<n) //replacing all position of that digit with 0\n                {\n                    if(t[i]==digit)\n                        t[i]=\'0\';\n                    i++;\n                }\n                break;\n            }\n        }\n        int mini = stoi(t);\n        return maxi-mini;\n        \n    }\n};\n```\n# Please upvote if you like this approach
['Math', 'String', 'C++']