✅ Short & Self Explanatory | 2 Approaches | C++ | Beginner friendly
Brute Force Approach\nTime: O(n^2) where n is size of nums\nSpace: O(1)\n\nclass Solution {\npublic:\n    int numOfPairs(vector<string>& nums, string target) {\
**Brute Force Approach**\n**Time: O(n^2) where n is size of nums**\n**Space: O(1)**\n```\nclass Solution {\npublic:\n    int numOfPairs(vector<string>& nums, string target) {\n        int ans=0;\n        for(int i=0;i<nums.size();i++){\n            for(int j=0;j<nums.size();j++){\n                if(i!=j and target == nums[i]+nums[j]){\n                    ans++;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```\n**Using unordered map**\n**Time: O(n + mk) where where n is size of nums, m is target size and k is the length of the resulting substring.\nSpace: O(n)**\n```\nclass Solution {\npublic:\n    int numOfPairs(vector<string>& nums, string target) {\n        int cnt=0;\n        int n=target.size();\n        unordered_map<string, int> map;\n        for(auto digit : nums)\n            map[digit]++;\n        \n        for(int i=0; i<target.size(); i++){\n            string s1=target.substr(0,i);\n            string s2=target.substr(i,n);\n            if(s1 == s2){\n               cnt+=map[s1]*(map[s2]-1);\n            }else{\n                cnt+=map[s1]*map[s2]; \n            }\n        }\n        return cnt;\n    }\n};\n```\n**Feel free to ask any question in the comment section.**\nI hope that you\'ve found the solution useful.\nIn that case, **please do upvote and encourage me** to on my quest to document all leetcode problems\uD83D\uDE03\nHappy Coding :)\n
['C', 'C++']