🧑‍🎓Less than 10 lines Code❤️‍🔥 Detailed Explanation ✅... Beats 💯% solutions on LeetCode 🐦‍🔥✨
Intuition\nFirst of all I got the intuition that I will have to keep a track of the frequency of words in both the given sentences and for that I can use map wh
# Intuition\nFirst of all I got the intuition that I will have to keep a track of the frequency of words in both the given sentences and for that I can use map where words will be mapped to there frequencies.\n\n![image.png](https://assets.leetcode.com/users/images/d17bcb40-fa66-4461-802d-bf018529bbd4_1726570781.6765237.png)\n\n\n# Approach\n- First create a vector of string datatype named `result` to store the words which are uncommon to both the sentences.\n- Then we can access each word of the sentences using `stringstream`.\n- Now for each word accessed from the sentences we can increment the frequency of that word.\n- Then traverse through the map and check for the word which has single frequency and if it is found then push that word to the `result` vector.\n- Finally, return `result`.\n\n# Complexity\n- **Time complexity:** O(N+M) \u231B\n\n- **Space complexity**: O(N+M) \uD83D\uDE80\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        stringstream ss1(s1), ss2(s2);\n        string word1, word2;\n        vector<string> result;\n        map<string, int> mp;\n        while(ss1>>word1) ++mp[word1];\n        while(ss2>>word2) ++mp[word2];\n        for(auto x: mp){\n            if(x.second==1) result.push_back(x.first);\n        }\n        return result;\n    }\n};\n```\n*Please upvote\uD83D\uDC4D if you found it helpful guys as it would encourage me to post more such solutions. \uD83D\uDE07*\n
['Hash Table', 'String', 'C++']