Very Easy and Beginner friendly 🎯📜
Intuition\nThe goal is to find words that appear only once in either of two given sentences and are not repeated in either sentence. We can solve this by splitt
# Intuition\nThe goal is to find words that appear only once in either of two given sentences and are not repeated in either sentence. We can solve this by splitting both sentences into arrays of words and identifying which words are unique across both arrays. A word is considered unique if it appears exactly once in one sentence and doesn\'t appear in the other.\n\n# Approach\nSplit the sentences: First, we split both input sentences into arrays of words.\nCheck uniqueness: For each word in the first sentence\'s array, check:\nWhether it appears more than once within the same array.\nWhether it appears in the other sentence\'s array. If it doesn\u2019t repeat in its own array and is not found in the other sentence\'s array, it is considered unique and added to the result list.\nSimilarly, repeat this process for the words in the second sentence\u2019s array.\nReturn the result: The result will be a list of words that are unique in both sentences.\n\n# Complexity\n- Time complexity:\nO(n^2), where n is the maximum of the lengths of the two sentences. This is because for each word, we compare it with every other word in both arrays.\n\n- Space complexity:\nO(n), where n is the total number of words across both sentences, as we are storing the result in an additional list.\n\n# Code\n```java []\nclass Solution {\n    public String[] uncommonFromSentences(String s1, String s2) {\n        List<String> list=new ArrayList<>();\n        String []a1=s1.split(" ");\n        String []a2=s2.split(" ");\n        String w1;\n        String w2;\n        boolean isfound=false;\n        for(int a=0;a<a1.length;a++){\n            isfound=false;\n            for(int b=0;b<a1.length;b++){\n                if(a!=b&&a1[a].equals(a1[b])){\n                    isfound=true;\n                } \n            }\n            for(int c=0;c<a2.length;c++){\n                if(a1[a].equals(a2[c])){\n                    isfound=true;\n                }\n            }\n            \n            if(!isfound){\n                list.add(a1[a]);\n            }\n        }\n        for(int a=0;a<a2.length;a++){\n            isfound=false;\n            for(int b=0;b<a2.length;b++){\n                if(a!=b&&a2[a].equals(a2[b])){\n                    isfound=true;\n                }\n            }\n            for(int c=0;c<a1.length;c++){\n                if(a2[a].equals(a1[c])){\n                    isfound=true;\n                }\n            }\n            if(!isfound){\n                list.add(a2[a]);\n            }\n        }\n        int len=list.size();\n        String []ans=new String[len];\n        for(int i=0;i<len;i++){\n            ans[i]=list.get(i);\n        }\n        return ans;\n    }\n}\n```
['Java']