Prefix and Suffix Counts
For each string, check if it\'s prefix and/or suffix of the target. Track the count of prefixes and suffixes for each position in the target.\n\n#### Approach 1
For each string, check if it\'s prefix and/or suffix of the target. Track the count of prefixes and suffixes for each position in the target.\n\n#### Approach 1: Multiply in the end\nWe count prefix and suffix matches, and multiply them in the end. Note that we need handle an edge case when the target is symmetric.\n\n**C++**\n```cpp\nint numOfPairs(vector<string>& nums, string t) {\n    int pref[101] = {}, suf[101] = {}, sz = t.size();\n    for (auto &n : nums)\n        if (n.size() < sz) {\n            pref[n.size()] += t.compare(0, n.size(), n) == 0;\n            suf[sz - n.size()] += t.compare(sz - n.size(), n.size(), n) == 0;\n        }\n    return inner_product(begin(pref), end(pref), begin(suf), 0) \n        - (t.substr(0, sz / 2) == t.substr(sz / 2) ? suf[sz / 2] : 0);\n} \n```\n\n#### Approach 2: Count as you go\n Unlike the first solution, here we accumulate the matches as we go. \n \n**C++**\n```cpp\nint numOfPairs(vector<string>& nums, string t) {\n    int pref[101] = {}, suf[101] = {}, res = 0;\n    for (auto &n : nums)\n        if (n.size() < t.size()) {\n            bool isPref = t.compare(0, n.size(), n) == 0;\n            bool isSuf = t.compare(t.size() - n.size(), n.size(), n) == 0;\n            res += (isPref ? suf[n.size()] : 0) + (isSuf ? pref[t.size() - n.size()] : 0);\n            pref[n.size()] += isPref;\n            suf[t.size() - n.size()] += isSuf;\n        }\n    return res;\n}\n```\n
['C']