✅ Beats 100.00%  || 0 ms 🔥|| JAVA || String || Easy Solution
Intuition\nThe problem asks to find uncommon words from two given sentences. An "uncommon word" is a word that appears exactly once in one of the sentences and 
# Intuition\nThe problem asks to find uncommon words from two given sentences. An "uncommon word" is a word that appears exactly once in one of the sentences and does not appear in the other sentence. To solve this, we need to determine the frequency of each word in both sentences combined. If a word appears exactly once, it is considered "uncommon."\n\n# Approach\n1. Split the sentences into words: Use the split(" ") method to  reak each sentence (s1 and s2) into individual words.\n2. Count word occurrences: Use a HashMap to store the frequency of each word from both sentences. For each word in both sentences, we either add it to the map or update its count if it already exists.\n3. Filter uncommon words: Iterate through the map to collect all words that have a count of exactly 1. These are the "uncommon" words.\n4. Return the result: Convert the list of uncommon words to a String[] array and return it.\n\n# Complexity\n- Time complexity:\nO(n + m)\n\n- Space complexity:\nO(n + m)\n\n# Code\n```java []\nclass Solution {\n    public String[] uncommonFromSentences(String s1, String s2) {\n        Map<String, Integer> mp = new HashMap<>();\n        \n        // Split both sentences into words\n        String[] s1Arr = s1.split(" ");\n        String[] s2Arr = s2.split(" ");\n        \n        // Add words from s1 to the map\n        for (String s : s1Arr) {\n            mp.put(s, mp.getOrDefault(s, 0) + 1); // Use getOrDefault to avoid null values\n        }\n        \n        // Add words from s2 to the map\n        for (String s : s2Arr) {\n            mp.put(s, mp.getOrDefault(s, 0) + 1); // Use getOrDefault to avoid null values\n        }\n        \n        // Find words that appear exactly once\n        List<String> result = new ArrayList<>();\n        for (Map.Entry<String, Integer> entry : mp.entrySet()) {\n            if (entry.getValue() == 1) {\n                result.add(entry.getKey());\n            }\n        }\n        \n        // Convert result list to array\n        return result.toArray(new String[0]);\n    }\n}\n```
['Hash Table', 'String', 'Counting', 'Java']