Simple java solution
\n\n# Complexity\n- Time complexity: O(n) where n is the length of the string \n\n- Space complexity: O(n) where n is the length of the string \n\n# Code\n\ncla
\n\n# Complexity\n- Time complexity: $$O(n)$$ where n is the length of the string \n\n- Space complexity: $$O(n)$$ where n is the length of the string \n\n# Code\n```\nclass Solution {\n    public int minMaxDifference(int num) {\n        char x[]=String.valueOf(num).toCharArray();\n        char y[]=String.valueOf(num).toCharArray();\n        char p=x[0],q=x[0];\n        for(int i=0;i<x.length;i++)\n        {\n            if(x[i]!=\'9\')\n            {\n                p=x[i];\n                break;\n            }\n        }\n        for(int i=0;i<x.length;i++)\n        {\n            if(x[i]==p)\n            {\n                x[i]=\'9\';\n            }\n        }\n        for(int i=0;i<x.length;i++)\n        {\n            if(y[i]==q)\n            {\n                y[i]=\'0\';\n            }\n        }\n        return Integer.parseInt(String.valueOf(x)) - Integer.parseInt(String.valueOf(y));\n    }\n}\n```
['String', 'Java']