StringStream ||Beats 100%
\n\n# Intuition\n Describe your first thoughts on how to solve this problem. \n\nTo find uncommon words between two sentences:\n\nCount Occurrences: Track how m
![image.png](https://assets.leetcode.com/users/images/a5bb931d-6b17-4681-9243-1fb21afffd42_1726543994.9880424.png)\n\n# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nTo find uncommon words between two sentences:\n\nCount Occurrences: Track how many times each word appears in both sentences combined.\nIdentify Uncommon Words: A word is uncommon if it appears exactly once in total and does not appear in both sentences.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nCount Words: Use a lambda function to iterate over each word in both sentences and maintain a count of each word using an unordered_map.\n\nThe lambda function processes each sentence by splitting it into words and updating the count in the map.\nIdentify Uncommon Words: Iterate through the unordered_map to identify words that appear exactly once.\n\nFor each word in the map, check if its count is 1. If it is, add it to the result vector.\nReturn Result: Return the vector of uncommon words.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n+m)\nwhere \n\uD835\uDC5B and \uD835\uDC5A are the lengths of the sentences.\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(k)\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        unordered_map<string,int>count;\n       \n        auto wordcount=[&](string& sentence){\n           string word;\n           stringstream ss(sentence);\n           while(ss>>word){\n            count[word]++;\n           }\n        };\n        wordcount(s1);\n        wordcount(s2);\n        vector<string>ans;\n        for(auto i=count.begin();i!=count.end();i++){\n            if(i->second==1){\n                ans.push_back(i->first);\n            }\n        }\n        return ans;\n\n    }\n};\n```
['C++']