Return Words Present in Exactly One Message
DiscordData Scientist · Technical ScreenLast updated
Find words appearing in exactly one of two messages using set symmetric difference while clarifying tokenization and case rules.
Return Words Present in Exactly One Message
Implement unique_string(msg1, msg2). Given two message strings, return a list of words that appear in exactly one message: the symmetric difference of the messages' word sets.
Repeated occurrences of a word within one message do not produce repeated words in the result. A word found in both messages is excluded. The exercise does not prescribe the order of the returned list, so different permutations of the same words are valid.
Clarifications
Agree on what counts as a word and whether comparison is case-sensitive before implementing. The prompt does not supply punctuation, tokenization, or case-normalization rules. Apply the agreed convention consistently to both messages.
Hints
Hint 1
Consider membership before frequency: The requested distinction depends on which messages contain a word.
Follow-up questions
- What happens when the two messages contain the same word several times each?
- Which tokenization and case rules would you clarify for punctuation or mixed-case text?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.