[Java] [Detailed Explanation]Using only array. Time Complexity O(n), Space Complexity O(1)
For any pair sub-sequence ascending, we need to know that the frequency of it will not decrease after changing.\n\nFor example, for sequence "22335", we have pa
For any pair sub-sequence **ascending**, we need to know that the frequency of it will not decrease after changing.\n\nFor example, for sequence `"22335"`, we have pair-frequency like `("23", 4), ("35", 2), ("25", 2)`. And if the t string is `"52323" `we should return false because `("23, 2"), ("35", 0), ("25", 0)` \'s frequency is less than the previous string. (Actually once we found that any one of the string is of less frequency we should return false)\n```\nclass Solution {\n    public boolean isTransformable(String s, String t) {\n        if (!equal(s, t)) return false;\n        int[] countS = new int[10];\n        int[] countT = new int[10];\n        int[][] prev = new int[10][10];\n        int[][] after = new int[10][10];\n        \n        for (int i = 0; i < s.length(); i++) {\n            int s1 = s.charAt(i) - \'0\';\n            int t1 = t.charAt(i) - \'0\';\n            countS[s1]++;\n            countT[t1]++;\n            \n\t\t\t// This step is to calculate how many digit less than s1/t1 occur before time i\n\t\t\t// Store the frequency pair into 2-d array\n            for (int j = 0; j < s1; j++) {\n                if (countS[j] == 0) continue;\n                prev[j][s1] += countS[j];\n\n            }\n            \n            for (int j = 0; j < t1; j++) {\n                if (countT[j] == 0) continue;    \n                after[j][t1] += countT[j];\n            }\n            \n        }\n        \n        for (int i = 0; i <= 8; i++) {\n            for (int j = i + 1; j <= 9; j++) {\n                if (prev[i][j] == 0) continue;\n\t\t\t\t// Check if any ascending pair\'s frequency has been reduced after modified.\n                if (after[i][j] < prev[i][j]) return false;\n            }\n        }\n        \n        return true;\n    }\n    \n\t// Judge whether the two strings has the same digits\n    public boolean equal(String s, String t) {\n        char[] sc = s.toCharArray();\n        char[] tc = t.toCharArray();\n        Arrays.sort(sc);\n        Arrays.sort(tc);\n        \n        for (int i = 0; i < s.length(); i++) {\n            if (sc[i] != tc[i]) return false;\n        }\n        \n        return true;\n    }\n}\n```
['Prefix Sum', 'Java']