Uncommon Words from Two Sentences

EasyStringshashing

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

A sentence is a string of lowercase words separated by single spaces. A word is **uncommon** if it appears exactly once in one of the sentences and does not appear at all in the other. Given two sentences s1 and s2, return a list of all uncommon words. The words may be returned in **any order**; if there are none, return an empty list.

Examples

Input: s1 = "this apple is sweet", s2 = "this apple is sour"
Output: ["sweet","sour"]
"sweet" and "sour" each occur once overall; the other words appear in both.
Input: s1 = "apple apple", s2 = "banana"
Output: ["banana"]
"apple" appears twice, so only "banana" is uncommon.

Constraints

  • 1 <= s1.length, s2.length <= 200
  • `s1` and `s2` consist of lowercase letters and single spaces
  • Neither sentence has leading or trailing spaces
  • Words are separated by exactly one space

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More hashing problems