intuitive proof of why:It's essentially bubble sort,
I will quickly explain why these methods work, while some don\'t.\n\nFirst the operation of subarray sorting is the same as the basic operation in bubble sort, 
I will quickly explain why these methods work, while some don\'t.\n\nFirst the operation of subarray sorting is the same as the basic operation in bubble sort, i.e. swap the two adjacent elements x, y if x > y.\n\nProof: if we can do bubble sort operation, then we can do subarray sorting as in bubble sort. Conversely, just sorting the adjacent 2 elements x, y will reduce to the bubble sort operation.\n\nPlease stop reading here, the following needs to be modified. See why here:\nhttps://leetcode.com/problems/check-if-string-is-transformable-with-substring-sort-operations/discuss/845059/More-methods-are-wrong-including-the-No1-in-the-contest%3A-231-132\n------------------------------\nNow for each string we need to count: for each character: how many elements on its left are smaller than itself. We want each corresponding number for s (dic1 in my codes) is smaller than or equal to that for t (dic2 in my codes). This (together with Counter(s) == Counter(t)) is the equivalent condition for this problem.\n\nBecause if so, you can start with the largest elements, move them up to the correct positions, without altering other elements values in dic1 and dic2. Once the largest numbers are done, then proceed to the second largest, etc. The converse is obvious, these number in s can only get bigger by the operations.\n\nThe problem with the "inversion method" is it counts the inversions with every numbers from 0-9, but ignoring different occurances of the same number, that\'s how I come up with 1331 and 3113. Both of them have two inversions on (1,3), but each 3 in 1331 contribute one inversion, while the second 3 in 3113 contributes two.\n\nAs a general advice, for a problem like that, always start with some necessary conditions, find as many conditions as you can that will definitely False,  and just submit it, maybe it is sufficient too. It took me 20 minutes in the contest to prove it though...\n\n```\nclass Solution:\n    def isTransformable(self, s: str, t: str) -> bool:\n        c1 = collections.Counter()\n        c2 = collections.Counter()\n\n        \n        dic1 = collections.defaultdict(list)\n        dic2 = collections.defaultdict(list)\n        for a, b in zip(s, t):\n            a = int(a)\n            b = int(b)\n            c1[a] += 1\n            c2[b] += 1\n            dic1[a].append(sum(c1[x] for x in range(a)))\n            dic2[b].append(sum(c2[x] for x in range(b)))\n        \n        if c1 != c2:\n            return False\n        for x in range(10):\n            for a, b in zip(dic1[x], dic2[x]):\n                if a > b:\n                    return False\n        return True\n```
[]