Ctrl K

Words Heard Only Once

Easy
Two people each said one line: first and second. Each line is made of lowercase English words separated by single spaces. Call a word lonely if, across both lines together, it was spoken exactly once: it appears a single time in one line and not at all in the other. Return all lonely words in any order.
Example 1
first="red fox runs fast", second="blue fox runs" → ['red', 'fast', 'blue']

"fox" and "runs" appear in both lines. "red" and "fast" occur once, only in the first, and "blue" once, only in the second.

Example 2
first="go go", second="stop" → ['stop']

"go" is said twice, so it does not count; only "stop" remains.

Constraints
  • 1 ≤ len(first), len(second) ≤ 200
  • Lines consist of lowercase English letters and spaces
  • No leading or trailing spaces; words are separated by exactly one space
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsNote From Clipped Letters EasyFirst One-Off Letter EasyWords From Letter Tiles EasyBalloon Signs From Letters EasyLetters Up and Down Easy
loading Python…
Input
first="red fox runs fast", second="blue fox runs"
Expected
['red', 'fast', 'blue']

Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.