Java simple solution beats 100%
Just maintain a map containing the freq. Now all we have to do is to check freq of needed suffix/prefix.  \n\nclass Solution {\n    public int numOfPairs(String
Just maintain a map containing the freq. Now all we have to do is to check freq of needed suffix/prefix.  \n```\nclass Solution {\n    public int numOfPairs(String[] nums, String target) {\n        Map<String, Integer> map = new HashMap<>();\n        int tot = 0;\n        for (int i = 0; i < nums.length; i++) {\n            if (target.startsWith(nums[i])) {\n                String sub = target.substring(nums[i].length());\n                if (map.containsKey(sub))\n                    tot += map.get(sub);\n            }\n           if (target.endsWith(nums[i])) {\n                String sub = target.substring(0, target.length()-nums[i].length());\n                if (map.containsKey(sub))\n                    tot += map.get(sub);\n            }\n            map.put(nums[i], map.getOrDefault(nums[i], 0)+1);\n        }\n        return tot;\n    }\n}\n```
[]