Prefix and Suffix frequency || C++ Easy to understand || Clean Code
\n# Code:\n\nclass Solution {\npublic:\n    int numOfPairs(vector<string>& nums, string target) {\n        \n        int t = target.size();\n        \n        v
\n# Code:\n```\nclass Solution {\npublic:\n    int numOfPairs(vector<string>& nums, string target) {\n        \n        int t = target.size();\n        \n        vector<int> prefix(t, 0), suffix(t, 0);\n        \n        int count = 0;\n        for(int i=0; auto& num : nums) {\n            int n = num.size();\n            \n            if(n >= t) continue;\n            \n            bool isPrefix = target.compare(0, n, num) == 0;\n            bool isSuffix = target.compare(t - n, n, num) == 0;\n            \n            if(isPrefix) count += suffix[n];\n            if(isSuffix) count += prefix[t-n-1];\n            \n            if(isPrefix) prefix[n-1]++;\n            if(isSuffix) suffix[t-n]++;\n            \n            i++;\n        }\n        \n        return count;\n    }\n};\n```\n\n**Complexity :**\n\n* **Time** : `O(N * n)` , \n\t* N is size of nums array and n is size(*avg*) of each num in nums\n\t* Since we are comparing each number with target, so we need to account that as well\n* **Space** : `O(N)`\n\n***If you find this helpful, do give it a like :)***
['String', 'C']