Count Common Words With One Occurrence

Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.

Example 1
Inputwords1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]
Output2
"leetcode" and "amazing" each appear exactly once in both arrays, while "is" appears twice in words1 and "as" does not appear in words2.
Example 2
Inputwords1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"]
Output0
There are no strings that appear in each of the two arrays.

Constraints

  • 1 <= words1.length, words2.length <= 1000
  • 1 <= words1[i].length, words2[j].length <= 30
  • words1[i] and words2[j] consists only of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate