It is as easier as this.
\n# 1) Optimal (HashMap): TC = O(n); SC = O(n)\n\n# Counter HashMap for easy working with the counts of nums:\nfrom collections import Counter\nfrequency = Coun
```\n# 1) Optimal (HashMap): TC = O(n); SC = O(n)\n\n# Counter HashMap for easy working with the counts of nums:\nfrom collections import Counter\nfrequency = Counter()\npairs = 0\n# Taking every num one by one and checking for required nums in HashMap:\nfor num in nums:\n\tpairs += frequency[target.removeprefix(num)] + frequency[target.removesuffix(num)]\n\t# `target.removeprefix(num)` & `target.removesuffix(num)` = required num for pair concat to be = target, why? ->\n\t# Input: nums = ["777", "7"], target = "7777"\n\t# Output: 2\n\t# Explanation: Valid pairs are:\n\t# - (0, 1): "777" + "7"\n\t# - (1, 0): "7" + "777"\n\tfrequency[num] += 1\nreturn pairs\n```\nUnderstood? \uD83D\uDE01\n[Link](https://github.com/samyak1409/DSA) to the GitHub Repository for similar explanations. Star it if you like it. :)
['Python']