Uncommon Words Finder
Given two strings A and B, return the words that are uncommon between the two. A word is considered 'uncommon' if it appears exactly once in one of the strings and does not appear in the other string.
[ "apple banana cherry", "banana kiwi mango" ]
Explanation. Words 'apple' and 'cherry' appear only in the first string, and 'kiwi' and 'mango' appear only in the second string.
[ "hello world", "hello" ]
Explanation. The word 'world' appears only in the first string and not in the second string.
[ "one two three", "four five six" ]
Explanation. All words are uncommon between the two strings.
[ "one two three", "two three four" ]
Explanation. Words 'one' and 'four' are the only uncommon words between the two strings.
Follow-up: How would you optimize your solution if both strings are very long?
Each string can consist of alphabetic characters and spaces only. Words within the string are separated by a single space. Strings are not guaranteed to be lowercase or uppercase consistently.
- Accepted
- 1/1
- Acceptance Rate
- 100.0%
- Views
- 1