C++/Java/Python O(n)
Intuition\nIf ch[i] > ch[j], we can swap these characters. In other words, we can move a character freely to the left, until it hits a smaller character, e.g.:\
**Intuition**\nIf `ch[i] > ch[j]`, we can swap these characters. In other words, we can move a character freely to the left, until it hits a smaller character, e.g.:\n\n"023**1**" > "02**1**3" > "0**1**23"\n\nSo, we do not need to sort anything, we just need to check if we can move required characters to the left to get the target string.\n\n> Note: we can also process the string right-to-left and move larger numbers right. In that case, we can just pop used indexes instead tracking them in a separate array `pos`. I though about it, but it appeared a bit harder to get right during the contest. If interested, check the solution by [0xFFFFFFFF](https://leetcode.com/0xFFFFFFFF/) in the comments below.\n\n**Algorithm**\nCollect indexes of all characters `0`-`9` of the source strings in `idx`. For each characters, we track which indexes we have used in `pos`.\n\nFor each character `ch` in the target string, check if we have it in `idx`. If so, verify that there are no smaller characters in front of it. To do that, we check the current idexes of all characters less than `ch`.\n\nIf the character can be moved, mark its index as used by advancing `pos[ch]`. \n\n**C++**\n```cpp\nbool isTransformable(string s, string t) {\n    vector<vector<int>> idx(10);\n    vector<int> pos(10);\n    for (int i = 0; i < s.size(); ++i)\n        idx[s[i] - \'0\'].push_back(i);\n    for (auto ch : t) {\n        int d = ch - \'0\';\n        if (pos[d] >= idx[d].size())\n            return false;\n        for (auto i = 0; i < d; ++i)\n            if (pos[i] < idx[i].size() && idx[i][pos[i]] < idx[d][pos[d]])\n                return false;\n        ++pos[d];\n    }\n    return true;\n}\n```\n\n**Java**\n```java\npublic boolean isTransformable(String s, String t) {\n    ArrayList<Integer> idx[] = new ArrayList[10];\n    int pos[] = new int[10];\n    for (int i = 0; i <= 9; ++i)\n        idx[i] = new ArrayList<Integer>();\n    for (int i = 0; i < s.length(); ++i)\n        idx[s.charAt(i) - \'0\'].add(i);\n    for (int i = 0; i < t.length(); ++i) {\n        int d = t.charAt(i) - \'0\';\n        if (pos[d] >= idx[d].size())\n            return false;\n        for (int j = 0; j < d; ++j)\n            if (pos[j] < idx[j].size() && idx[j].get(pos[j]) < idx[d].get(pos[d]))\n                return false;        \n        ++pos[d];\n    }\n    return true;\n}\n```\n**Python**\n```python\ndef isTransformable(self, s: str, t: str) -> bool:\n\tidx, pos = [[] for _ in range(10)], [0 for _ in range(10)]\n\tfor i, ch in enumerate(s):\n\t\tidx[int(ch)].append(i)\n\tfor ch in t:\n\t\td = int(ch)\n\t\tif pos[d] >= len(idx[d]):\n\t\t\treturn False\n\t\tfor i in range(d):\n\t\t\tif pos[i] < len(idx[i]) and idx[i][pos[i]] < idx[d][pos[d]]:\n\t\t\t\treturn False\n\t\tpos[d] += 1\n\treturn True\n```\n**Complexity Analysis**\n- Time: O(n) - we go through each string once.\n- Memory: O(n) - to hold indices from the source string.
[]