LeetCode 884, Easy. Topics: Hash Table, String, Counting. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 14 parametrized pytest cases, and a playground notebook:
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
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, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026