Python brute force and optimized prefix sum method
\n\'\'\'\nBrute:\nclass Solution:\n    def numOfPairs(self, nums: List[str], target: str) -> int:\n        n,count = len(nums),0\n        for i in range(n):\n  
```\n\'\'\'\nBrute:\nclass Solution:\n    def numOfPairs(self, nums: List[str], target: str) -> int:\n        n,count = len(nums),0\n        for i in range(n):\n          for j in range(0,n):\n            if i!=j:\n              if nums[i]+nums[j]==target:\n                # print(nums[i],nums[j])\n                count+=1\n        return count\n\'\'\'\n\nclass Solution:\n    def numOfPairs(self, nums: List[str], target: str) -> int:\n        n,count = len(nums),0\n        h = {}\n        \n        \'\'\'\n        We use two passes to prevent counting self pairs like (i,i) and   (j,j).\n        In both the passes,we build the Counter dictionary as we iterate making sure that we dont add nums[i] only after checking for target-nums[i].\n        Doing two pass ensures that (i,j) and (j,i) if valid are counted.\n        \'\'\'\n        #foward pass\n        for k in nums:\n          if target[0:len(k)]==k:\n            nk = target[len(k):len(target)]\n            if nk in h:\n              count+=h[nk]\n          if k in h: h[k]+=1\n          else: h[k]=1\n              \n        #backward pass\n        h.clear()\n        for k in nums[::-1]:\n          if target[0:len(k)]==k:\n            nk=target[len(k):len(target)]\n            if nk in h:\n              count+=h[nk]\n          if k in h: h[k]+=1\n          else: h[k]=1\n          \n        return count\n```
['Python']