> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Uncommon Words from Two Sentences

> Tested Python solution for LeetCode 884 with 14 pytest cases. Generate a practice environment with lcpy.

LeetCode 884, [Easy](/catalog/easy). Topics: [Hash Table](/catalog/topics/hash-table), [String](/catalog/topics/string), [Counting](/catalog/topics/counting). [View on LeetCode](https://leetcode.com/problems/uncommon-words-from-two-sentences/description/).

Generate this problem as a practice environment: tested reference solution, 14 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 884   # by problem number
lcpy gen -s uncommon_words_from_two_sentences   # by problem name
```

## Problem

A \<strong>sentence\</strong> is a string of single-space separated words where each word consists only of lowercase English letters.\</p>

\<p>A word is \<strong>uncommon\</strong> if it appears exactly once in one of the sentences, and \<strong>does not appear\</strong> in the other sentence.\</p>

\<p>Given two sentences \<code>s1\</code> and \<code>s2\</code>, return \<em>a list of all the \<strong>uncommon words\</strong>\</em>. You may return the answer in any order.

### Examples

```
Input: s1 = "this apple is sweet", s2 = "this apple is sour"
Output: ["sweet","sour"]
```

```
Input: s1 = "apple apple", s2 = "banana"
Output: ["banana"]
```

### Constraints

* 1 \<= s1.length, s2.length \<= 200
* s1 and s2 consist of lowercase English letters and spaces.
* s1 and s2 do not have leading or trailing spaces.
* All the words in s1 and s2 are separated by a single space.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/uncommon_words_from_two_sentences/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/uncommon_words_from_two_sentences/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections import Counter


class Solution:
    # Time: O(m + n)
    # Space: O(m + n)
    def uncommon_from_sentences(self, s1: str, s2: str) -> list[str]:
        counts = Counter((s1 + " " + s2).split())
        return [word for word, count in counts.items() if count == 1]
```

## Complexity

| Time | Space |
| - | - |
| O(m + n) | O(m + n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.