100% beats - Easy C++ explained with comments
Intuition\nThe idea is to store the number in vector then simply replace the starting digits with 9 to maximise and with 0 to minimse\n\n# Approach\nInput : 118
# Intuition\nThe idea is to store the number in vector then simply replace the starting digits with 9 to maximise and with 0 to minimse\n\n# Approach\n**Input : 11891**\nTo maximise the number\nIn a loop..\ncheck for the first digit if it is equal to 9 then do nothing... go for the next digit of vector again check if it is equal 9 or not...if it is not equal to 9 then store the current digit in some \'temp\' named variable\n**Here temp = 1;**\nand \'break\'..then in the next loop replace all the digit with 9 if the digit is equal to variable \'temp\' i.e all 1 will be replaced with 9\n\n\nReason we are checking with 9 is because if first digit is 9 then there is no need to do anything go for the next non 9 digit\n like 99881 will be be 99991(maximum)\n\n**To minimise** simply hold the starting digit in temp2 variable and replace wherver it is found in the vector\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n\n\nclass Solution {\npublic:\n    int minMaxDifference(int n) {\n        vector<int> v;  \n        vector<int> vt;\n        while(n>0)\n        {\n            // pushing at begining\n              v.insert(v.begin(),n%10 );\n              vt.insert(vt.begin(),n%10 );\n            n=n/10;\n        }\n        \n        int temp=0;\n        //maximising\n        for(int i=0; i<v.size(); i++)\n        {\n            // do nothing if 9 is there\n            if(v[i]==9)\n            continue;\n            else if(v[i]!=9)\n            {\n                // break we don\'t need to go further\n                temp=v[i];\n                break;\n            }\n        }\n        for(int i=0; i<v.size(); i++)\n        {\n             \n            if(temp==v[i])\n            {\n                v[i]=9;\n            }\n        }\n        // minimising by replacing wiht 0\n        int temp2=vt[0];\n        for(int i=0; i<vt.size(); i++)\n        {        \n            if(temp2==vt[i])\n            {\n                vt[i]=0;\n            }\n        }\n        // converting vector of numbers into number\n        int max = 0, min=0;\n        for (int i=0; i<v.size(); i++ ) \n            max = max * 10 + v[i];\n        \n            int num2 = 0;\n        for (int i=0; i<vt.size(); i++) \n            min = min * 10 + vt[i];\n        \n      \n        return max-min;\n    }  \n};
['Array', 'C', 'C++']