java | o(n)
Case 1: Return false if length of 2 strings vary.\n2. Case 2: Return false if all characters in one string is not present same number of times in the other stri
1. Case 1: Return false if length of 2 strings vary.\n2. Case 2: Return false if all characters in one string is not present same number of times in the other string.\n3. Case 3: \n\t1. Maintain cnt array for two string and increment the count as you traverse the strings.\n\t2. Sub case 1:\n\t\t1. If current character in string s has already occured in string t and doesn\'t have match in s till now, then the unmatched characters in s till now should only be greater than current character encountered in s.(based on problem statement - ascending order.) \n\t\t2. Else return false.\n\t3. Sub case 2:\n\t\t1. If the current character in string t matches any of the characters in s till now, there should be no unmatched characters in t till now that is greater than current character in t. (ascending order.)\n\t\t2. Else return false.\n\t4. If still the program didn\'t return, return true atlast.\n\n```\nclass Solution {\n    public boolean isTransformable(String s, String t) {\n        int n=s.length();\n        if(n!=t.length())\n        {\n            return false;\n        }\n        int[] cnt=new int[10];\n        for(int i=0; i<n; i++)\n        {\n            cnt[s.charAt(i)-\'0\']++;\n        }\n        for(int i=0; i<n; i++)\n        {\n            cnt[t.charAt(i)-\'0\']--;\n        }\n        for(int i=0; i<10; i++)\n        {\n            if(cnt[i]!=0)\n            {\n                return false;\n            }\n        }\n        int[] sCnt=new int[10];\n        int[] tCnt=new int[10];\n        for(int i=0; i<n; i++)\n        {\n            int sAsci=s.charAt(i)-\'0\';\n            int tAsci=t.charAt(i)-\'0\';\n            sCnt[sAsci]++;\n\n            if(tCnt[sAsci]>=sCnt[sAsci] || (sAsci==tAsci && tCnt[sAsci]+1>=sCnt[sAsci]))\n            {\n                int rem=0;\n                for(int j=0; j<sAsci; j++)\n                {\n                    if(sCnt[j]-tCnt[j]>0)\n                    {\n                        rem++;\n                    }\n                }\n                if(rem>0)\n                {\n                    return false;\n                }\n            }\n            if(sCnt[tAsci]>=tCnt[tAsci]+1)\n            {\n                int rem=0;\n                for(int j=tAsci; j<10; j++)\n                {\n                    if(tCnt[j]-sCnt[j]>0)\n                    {\n                        rem++;\n                    }\n                }\n                if(rem>0)\n                {\n                    return false;\n                }\n            }\n            tCnt[tAsci]++;\n        }\n        return true;\n    }\n}\n```
[]