Simple Java Code ☠️
Code\njava []\nclass Solution {\n    public String[] uncommonFromSentences(String s1, String s2) {\n        String[] arr1 = s1.split(" ");\n        String[] arr
# Code\n```java []\nclass Solution {\n    public String[] uncommonFromSentences(String s1, String s2) {\n        String[] arr1 = s1.split(" ");\n        String[] arr2 = s2.split(" ");\n        String[] arr = new String[arr1.length + arr2.length];\n        for(int i=0;i<arr1.length;i++){\n            arr[i] = arr1[i];\n        }\n        for(int i=0,j=arr1.length;i<arr2.length;i++,j++){\n            arr[j] = arr2[i];\n        }\n        HashSet<String> set = new HashSet<>();\n        HashSet<String> s = new HashSet<>();\n        for(int i=0;i<arr.length;i++){\n            if(!s.isEmpty() && s.contains(arr[i])){\n                continue;\n            }\n            if(!set.isEmpty() && set.contains(arr[i])){\n                set.remove(arr[i]);\n                s.add(arr[i]);\n            }\n            else{\n                set.add(arr[i]);\n            }\n        }\n        String[] res = new String[set.size()];\n        int j=0;\n        for (String i : set) {\n            res[j] = i;\n            j++;\n        }\n        return res;\n    }\n}\n```\n\n\n\n\n### Explanation:\n\n1. **Splitting Sentences into Words**:\n   ```java\n   String[] arr1 = s1.split(" ");\n   String[] arr2 = s2.split(" ");\n   ```\n   - The sentences `s1` and `s2` are split by spaces to extract individual words.\n   - `arr1` will contain all the words from sentence `s1`, and `arr2` will contain all the words from sentence `s2`.\n\n2. **Merging Words into One Array**:\n   ```java\n   String[] arr = new String[arr1.length + arr2.length];\n   for(int i=0;i<arr1.length;i++){\n       arr[i] = arr1[i];\n   }\n   for(int i=0,j=arr1.length;i<arr2.length;i++,j++){\n       arr[j] = arr2[i];\n   }\n   ```\n   - A new array `arr` is created to store all the words from both sentences.\n   - First, all words from `arr1` (from `s1`) are added to `arr`.\n   - Then, all words from `arr2` (from `s2`) are added to the remaining positions of `arr`.\n\n3. **Finding Uncommon Words**:\n   ```java\n   HashSet<String> set = new HashSet<>();\n   HashSet<String> s = new HashSet<>();\n   for(int i=0;i<arr.length;i++){\n       if(!s.isEmpty() && s.contains(arr[i])){\n           continue;\n       }\n       if(!set.isEmpty() && set.contains(arr[i])){\n           set.remove(arr[i]);\n           s.add(arr[i]);\n       } else {\n           set.add(arr[i]);\n       }\n   }\n   ```\n   - Two `HashSet`s are used: `set` and `s`.\n   - `set` stores the words that have been seen once so far.\n   - `s` stores the words that have been seen more than once.\n   - For each word in the combined array `arr`:\n     - If the word is in `s`, it means the word has already been encountered more than once, so we skip further processing for that word.\n     - If the word is in `set`, it means this is the second time we are encountering the word, so we remove it from `set` (as it is no longer uncommon) and add it to `s`.\n     - Otherwise, we add the word to `set`, indicating that this is the first time we are encountering it.\n\n4. **Storing the Result**:\n   ```java\n   String[] res = new String[set.size()];\n   int j=0;\n   for (String i : set) {\n       res[j] = i;\n       j++;\n   }\n   return res;\n   ```\n   - At this point, `set` contains all the words that are uncommon (i.e., appeared only once between both sentences).\n   - A new array `res` is created with the same size as `set`, and the elements from `set` are transferred to `res`.\n   - The result is then returned as an array of uncommon words.\n\n### Key Points:\n- The code identifies uncommon words by splitting the sentences, merging them into a single array, and then using two `HashSet`s to track words seen exactly once and words seen more than once.\n- The final set of uncommon words is extracted and returned.\n\n### Time Complexity:\n- **O(n)**, where `n` is the total number of words in both sentences combined. This includes splitting the sentences, merging the arrays, and processing the words with `HashSet` operations.\n\n### Space Complexity:\n- **O(n)**, due to the storage of words in `HashSet` and the final result array.\n\n\n
['Hash Table', 'String', 'Java']