Beats 100% Hash Map Approach Using istringstream
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem asks to find uncommon words from two sentences. An uncommon word is a word 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem asks to find uncommon words from two sentences. An uncommon word is a word that appears exactly once in one of the sentences and does not appear in the other. To solve this, we need to count the occurrences of each word in both sentences and then find the words that appear only once in total.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1) Store word frequencies: We use an unordered map to store the frequency of each word. We iterate through both sentences and add the words to the map while keeping track of how many times each word appears.\n\n2) Parse the sentences: Using istringstream, we split both input sentences (s1 and s2) into individual words and increment their count in the map. For each word we encounter, if it is already present in the map, we increment its frequency.\n\n3) Filter uncommon words: Once we have the frequency of each word, we iterate over the map. Any word that has a frequency of exactly 1 (i.e., it appears only once across both sentences) is added to the result.\n\n4) Return result: The words that appear exactly once are stored in a vector, which is returned as the answer.\n\n# Complexity\n# Time complexity: O(n+m+k)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n- Splitting and storing words: Splitting both sentences into words using istringstream takes O(n + m), where n is the length of s1 and m is the length of s2.\n- Filling the unordered map: Each word insertion or lookup in the unordered map takes O(1) on average. So, inserting all the words will take O(k), where k is the total number of words in both sentences combined.\n- Traversing the map: We then iterate through the map to find uncommon words, which takes O(k) since we check each word\'s frequency.\n- Thus, the total time complexity is O(n + m + k), where n and m are the lengths of the two input strings, and k is the total number of words in both sentences.\n\n# Space complexity: O(n+m+k)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n- Unordered map: We use an unordered map to store the frequency of each word. In the worst case, if all words are unique across both sentences, the map will store every word, so the space required is O(k), where k is the total number of unique words in both sentences.\n\n- String streams and temporary variables: The space used by the istringstream objects and temporary strings is proportional to the size of the input strings, which is O(n + m), where n is the length of s1 and m is the length of s2.\n\n- Result vector: The space used by the result vector depends on the number of uncommon words, which can also be O(k) in the worst case.\n\n- Therefore, the total space complexity is O(n + m + k), where n and m are the lengths of the two input strings, and k is the number of unique words in both sentences.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        unordered_map<string, int> mpp;\n        istringstream iss(s1);\n        string temp;\n        while(iss>>temp)\n        {\n            mpp[temp]++;\n        }\n        istringstream iss2(s2);\n        temp.clear();\n        while(iss2>>temp)\n        {\n            mpp[temp]++;\n        }\n        vector<string> ans;\n        for(auto it: mpp)\n        {\n            if(it.second==1)\n                ans.push_back(it.first);\n        }\n        return ans;\n    }\n};\n```
['Hash Table', 'String', 'C++']