Python O(N*7^4) = O(2400N) by computing all possible neighbors
For each n in nums, find all possible neighbors by doing all possible double swaps.  (This is a quartic loop BUT the limit of each loop is 7, so it becomes O(24
For each `n` in `nums`, find all possible neighbors by doing all possible double swaps.  (This is a quartic loop BUT the limit of each loop is 7, so it becomes `O(2400N)` complexity since `7^4=2401`).\nKeep track of every number seen already (simple hashmap/counter).\nThen for each `n` in `nums`, put `n`, all single swap values possible, and all double swap values possible into a set. There\'s only 2401+49+1 possible at most for each `n` (in reality much less, but that\'s not important since we have a clear upper bound).\nGo through this set of possible neighbors, and if it\'s been seen already in `nums` then increment by the number of times it was seen. \n```\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        C={}\n        ret=0\n\n        for n in nums:\n            n_Neighbors=set([n])            \n            L=list(str(n)) # convert to a list so we can swap elements\n            while len(L)<7: L=[\'0\']+L # add zeros beforehand\n            for i in range(7):\n                for j in range(i):\n                    L[i],L[j]=L[j],L[i]\n                    n_Neighbors.add(int( \'\'.join(L)))\n                    for k in range(7):\n                        for l in range(k):\n                            L[k],L[l] =L[l],L[k]\n                            n_Neighbors.add(int( \'\'.join(L)))\n                            L[k],L[l] =L[l],L[k]\n                    L[i],L[j]=L[j],L[i]\n                            \n\n            for x in n_Neighbors:\n                ret+=C.get(x,0)\n            C[n]=C.get(n,0)+1\n        return ret\n ```
[]