✨ Clean Solution || Beat's  100% || Easy to Understand || User Friendly || Maps & Frequency
\n\n## Problem Statement\nGiven two sentences s1 and s2, we need to find all uncommon words. An uncommon word is defined as one that:\n- Appears exactly once in
![image.png](https://assets.leetcode.com/users/images/15836801-abb8-4ad2-bb19-2e0a4a95babb_1726549591.4684155.png)\n\n## Problem Statement\nGiven two sentences `s1` and `s2`, we need to find all uncommon words. An uncommon word is defined as one that:\n- Appears **exactly once** in either `s1` or `s2`, and\n- Does **not** appear in both sentences.\n\nThe goal is to return these uncommon words in a list, and the order of the words doesn\'t matter.\n\n\n\n## Approach\n### Key Idea\n1. **Word Frequency Counting**: We can approach this problem by counting how many times each word appears across both sentences.\n2. **Check Frequency**: After collecting word frequencies, we simply extract the words that appear **exactly once**.\n\n### Steps:\n1. **Helper Function**: We create a helper function `helpme` to take each word from a sentence and update a frequency map (`unordered_map`).\n2. **Merge Frequencies**: Apply the helper function to both `s1` and `s2`, combining the results into a single map.\n3. **Filter Uncommon Words**: After populating the frequency map, we loop through it and collect all the words that occur exactly once.\n\n### Code\n```cpp\nclass Solution {\npublic:\n    // Helper function to populate the frequency map\n    void helpme(unordered_map<string, int>& mymap, string& s1) {\n        string temp = "";\n        for (int i = 0; i < s1.size(); i++) {\n            temp = "";\n            // Extract each word\n            while (s1[i] != \' \' && i < s1.size()) {\n                temp += s1[i];\n                i++;\n            }\n            mymap[temp]++;  // Update word count in the map\n        }\n    }\n\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        unordered_map<string, int> mymap;\n        \n        // Count frequencies for both sentences\n        helpme(mymap, s1);\n        helpme(mymap, s2);\n        \n        vector<string> ans;\n        // Collect words that appear exactly once\n        for (pair<string, int> check : mymap) {\n            if (check.second == 1) {\n                ans.push_back(check.first);\n            }\n        }\n        \n        return ans;  // Return the list of uncommon words\n    }\n};\n```\n\n### Cleanliness of the Code\n- **Helper Function**: The function `helpme` keeps the code modular and reusable, as it abstracts the process of counting word frequencies from a sentence.\n- **Minimal Loops**: The main logic operates in a simple and readable way, avoiding any unnecessary complexity.\n- **Efficient**: Using an `unordered_map` ensures that both insertion and lookup operations run in \\(O(1)\\), making the solution fast even for the upper constraint limits.\n\n### Complexity\n- **Time Complexity**:  \n  The time complexity is \\(O(m + n)\\), where \\(m\\) is the length of `s1` and \\(n\\) is the length of `s2`. We traverse both strings once and process each word in constant time.\n  \n- **Space Complexity**:  \n  The space complexity is \\(O(m + n)\\) as we store all words from both sentences in the `unordered_map`.\n\n
['Hash Table', 'String', 'Counting', 'C++']