[Java O(n) Two Pointers] Idea explained.
We start from the largest character \'9\'. A \'9\' at index i in s can only be moved to index j in t, where j >= i. i.e. The largest character can only be moved
We start from the largest character \'9\'. A \'9\' at index i in s can only be moved to index j in t, where j >= i. i.e. The largest character can only be moved to right or not moved because we are sorting substrings in ascending order.\n\nAfter we deal with \'9\', just remove all \'9\'s from both s and t and do the same check for \'8\', \'7\',....\nThe run time is O(10 * n) because only \'0\' - \'9\' are in the strings.\n\nHere\'s the java code.\n\t\n\tclass Solution {\n    public boolean isTransformable(String s, String t) {\n        return helper(s, t, \'9\');\n    }\n    \n    private boolean helper(String s, String t, char c) {\n        if (!Character.isDigit(c)) return true;\n        int i = 0;\n        int j = 0;\n        while (i < s.length() && j < t.length()) {\n            while (i < s.length() && s.charAt(i) != c) {\n                i++;\n            }\n            \n            while (j < t.length() && t.charAt(j) != c) {\n                j++;\n            }\n            \n            if (i == s.length() && j == t.length()) {\n                return helper(s.replaceAll("" + c, ""), t.replaceAll("" + c, ""), (char)(c - 1));\n            }\n            \n            if (i == s.length() || j == t.length()) return false;\n            if (i > j) {\n                return false;\n            }\n            i++;\n            j++;\n        }\n        return helper(s.replaceAll("" + c, ""), t.replaceAll("" + c, ""), (char)(c - 1));\n    }\n\t}
[]