[Java/Python 3] One pass O(NM) HashTable codes w/ analysis.
java\n    public int numOfPairs(String[] nums, String target) {\n        int cnt = 0, n = target.length();\n        Map<Integer, Integer> prefix = new HashMap<>
```java\n    public int numOfPairs(String[] nums, String target) {\n        int cnt = 0, n = target.length();\n        Map<Integer, Integer> prefix = new HashMap<>(), suffix = new HashMap<>();\n        for (String num : nums) {\n            int sz = num.length();\n            if (target.startsWith(num)) {\n                cnt += suffix.getOrDefault(n - sz, 0);\n            }\n            if (target.endsWith(num)) {\n                cnt += prefix.getOrDefault(n - sz, 0);\n            }\n            if (target.startsWith(num)) {\n                prefix.put(sz, 1 + prefix.getOrDefault(sz, 0));\n            }\n            if (target.endsWith(num)) {\n                suffix.put(sz, 1 + suffix.getOrDefault(sz, 0));\n            }\n        }\n        return cnt;\n    }\n```\n```python\n    def numOfPairs(self, nums: List[str], target: str) -> int:\n            prefix, suffix = Counter(), Counter()\n            cnt = 0\n            for num in nums:\n                if target.startswith(num):\n                    cnt += suffix[len(target) - len(num)]\n                if target.endswith(num):\n                    cnt += prefix[len(target) - len(num)]\n                if target.startswith(num):\n                    prefix[len(num)] += 1\n                if target.endswith(num):\n                    suffix[len(num)] += 1\n            return cnt\n```\n**Analysis:**\n\nLet `N = nums.length`, `M` be the average size of the digits in `nums`, and `T = target.length()`, then each `startsWith()` cost time O(min(M, T)), therefore the total time is `O(N * M)`, space cost `O(N)`.
['Java', 'Python3']