Bhai of cin -> stringstream + Full Map Concept, Chalo aao smjhe [ Beats 100% ]
Youtube Explanation \nWill Soon to be on Youtube Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\n> Start Points,\nFor Beginner : 00:00\nFor Non-Str
# Youtube Explanation \nWill Soon to be on Youtube Channel : https://www.youtube.com/@Intuit_and_Code\nEdited:\n> Start Points,\nFor Beginner : 00:00\nFor Non-StringStream Concept : 10:53\nFor StringString Concept : 18:51\n\nhttps://youtu.be/nrSDo-l_vZg?si=iDCoL-YSFnwNDADJ\n\n# Intuition & Approach\n> Jump on whichever Section You need to Learn, as it include beginner\'s Concepts\n\n![image.png](https://assets.leetcode.com/users/images/2efdc982-173b-4269-806e-b71d2380749c_1726539452.1513517.png)\n![image.png](https://assets.leetcode.com/users/images/00b20ba4-e8d1-45e7-a181-259d50638a00_1726539465.9745932.png)\n![image.png](https://assets.leetcode.com/users/images/6d2df854-4f7d-4331-997d-875bc3c78704_1726539505.819187.png)\n![image.png](https://assets.leetcode.com/users/images/60bd30e7-d710-4efa-824e-58839f77ecce_1726539517.1721787.png)\n![image.png](https://assets.leetcode.com/users/images/c929ddfd-024e-4266-b74c-53205c7d007a_1726539526.7344904.png)\n![image.png](https://assets.leetcode.com/users/images/cf902f8d-e0ab-4d92-8d3f-5b8af5979fd3_1726539538.1302931.png)\n![image.png](https://assets.leetcode.com/users/images/fe5f5948-495d-4dc0-8089-af04cc7082c7_1726539557.9338334.png)\n\n![image.png](https://assets.leetcode.com/users/images/644abf46-5992-405b-8ee0-00b1821da783_1726540643.378927.png)\n\n# Code - 01 [ Without String-Stream ]\n``` C++ []\nclass Solution {\npublic:\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        // we need to find unique occurences\n        string s = s1 + " " + s2;\n\n        cout<<s1.max_size();\n\n        // store all words from s\n        unordered_map<string,int> um;\n        string tmp="";\n        for(auto& val : s){ // similar to, i=0;i<s.size();i++\n            if(val == \' \'){\n                um[tmp]++;\n                tmp = "";\n            }\n            else{\n                tmp += val; // denotes, val = s[i]\n            }\n        }\n        \n        // condition needed if empty string allowed\n        if(tmp != ""){\n            um[tmp]++;\n            tmp = "";\n        }\n\n        // check unique means single count\n        vector<string> ans;\n        for(auto& val:um){ // auto it=um.begin();it<um.end();it++\n\n            // val.first = apple, val.second = 2\n\n            if(val.second==1){\n                ans.emplace_back(val.first); // can use push_back also                \n            }\n\n        }\n\n        return ans;\n    }\n};\n```\n``` java []\npublic List<String> uncommonFromSentences(String s1, String s2) {\n        // Concatenate both sentences with a space\n        String s = s1 + " " + s2;\n        \n        // Create a map to store the word counts\n        Map<String, Integer> wordCount = new HashMap<>();\n        \n        // Split the combined string into words\n        String[] words = s.split(" ");\n        \n        // Count the occurrences of each word\n        for (String word : words) {\n            wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);\n        }\n        \n        // Create a list to store the uncommon words (those with a count of 1)\n        List<String> result = new ArrayList<>();\n        \n        for (Map.Entry<String, Integer> entry : wordCount.entrySet()) {\n            if (entry.getValue() == 1) {\n                result.add(entry.getKey());\n            }\n        }\n        \n        return result;\n    }\n```\n# Why and How Using stringstream help ?\n![image.png](https://assets.leetcode.com/users/images/1adeff20-3514-4140-a286-e75ac0affbbe_1726539576.8789907.png)\n![image.png](https://assets.leetcode.com/users/images/9a8d56bf-8134-4c24-a965-88c569f869d9_1726539599.1401331.png)\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<string> uncommonFromSentences(string s1, string s2) {\n        // we need to find unique occurences\n        string s = s1 + " " + s2 + " ";\n        stringstream str(s);\n\n        cout<<s1.max_size();\n\n        // store all words from s\n        unordered_map<string,int> um;\n        string tmp;\n        while(str>>tmp){\n            um[tmp]++;\n        }\n\n        // check unique means single count\n        vector<string> ans;\n        for(auto& val:um){ // auto it=um.begin();it<um.end();it++\n\n            // val.first = apple, val.second = 2\n\n            if(val.second==1){\n                ans.emplace_back(val.first); // can use push_back also                \n            }\n\n        }\n\n        return ans;\n    }\n};\n```\n``` java []\nclass Solution {\n    public List<String> uncommonFromSentences(String s1, String s2) {\n        // Concatenate both sentences with a space\n        String s = s1 + " " + s2;\n        \n        // Create a map to store the word counts\n        Map<String, Integer> wordCount = new HashMap<>();\n        \n        // Split the combined string into words\n        String[] words = s.split(" ");\n        \n        // Count the occurrences of each word\n        for (String word : words) {\n            wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);\n        }\n        \n        // Create a list to store the uncommon words (those with a count of 1)\n        List<String> result = new ArrayList<>();\n        \n        for (Map.Entry<String, Integer> entry : wordCount.entrySet()) {\n            if (entry.getValue() == 1) {\n                result.add(entry.getKey());\n            }\n        }\n        \n        return result;\n    }\n```\n> Sadly Can\'t Think of any Brute-Force Today !! \uD83E\uDD72\n
['Hash Table', 'String', 'Counting', 'C++', 'Java']