> For the complete documentation index, see [llms.txt](https://programming.arora-aditya.com/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://programming.arora-aditya.com/leetcode/hash-table/884.-uncommon-words-from-two-sentences.md).

# 884. Uncommon Words from Two Sentences

## Approach 1: Counting

```python
class Solution(object):
    def uncommonFromSentences(self, A, B):
        """
        https://leetcode.com/problems/uncommon-words-from-two-sentences/description/
        :type A: str
        :type B: str
        :rtype: List[str]
        """
        
        count = {}
        for word in A.split():
            count[word] = count.get(word, 0) + 1
        for word in B.split():
            count[word] = count.get(word, 0) + 1
        return [word for word in count if count[word] == 1]
```

For both of the arrays we will simply count the number of times a word occurs. If in the end a word has a count of one then we can return a list of those words.

> **Time Complexity:** *O(M+N)*
>
> **Space Complexity:** O(M+N)
