324. Uncommon Words from Two Sentences

Easy
Combined Frequency Map
Hashing

Problem

A word is uncommon if it appears exactly once in one sentence and does not appear in the other sentence. Given two space-separated sentences s1 and s2, return all uncommon words in any order.

Examples

Example 1

Input: "this apple is sweet", "this apple is sour"
Output: ["sweet","sour"]

Example 2

Input: "apple apple", "banana"
Output: ["banana"]

Example 3

Input: "a", "b"
Output: ["a","b"]
Constraints

1 <= s1.length, s2.length <= 200

Sentences contain lowercase English words separated by single spaces.

Hints

?? Count words from both sentences in one frequency map.

?? A word is uncommon exactly when its combined frequency is one.

Expected Complexity
Time: O(total words)
Space: O(total distinct words)
Follow-up

Can you produce the result while using only one hash map?

Practice Notes

Attempts: 0

Time spent: 0min

Hints used: 0

00:00
Loading...
Case 1
Case 2
Case 3
Input
"this apple is sweet", "this apple is sour"
Expected
["sweet","sour"]