Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count Common Words With One Occurrence

XPChallenge Points: 10
levelLevel: Easy

You are given two arrays of strings: words1 and words2.
A word is considered valid if:

  1. It appears exactly once in words1, and

  2. It appears exactly once in words2.

Your task is to count how many words satisfy both conditions.

Example 1:

Input: words1 = ["leetcode", "is", "amazing", "as", "is"] words2 = ["amazing", "leetcode", "is"]

Output: 2

Explanation:

"leetcode" → appears once in both → count it "amazing" → appears once in both → count it "is" → appears twice in words1 → not counted "as" → appears once in words1, zero in words2 → not counted Total: 2

Example 2:

Input: words1 = ["b","bb","bbb"] words2 = ["a","aa","aaa"]

Output: 0

Explanation:

No word appears in both arrays → result is 0

Example 3:

Input: words1 = ["a","ab"] words2 = ["a","a","a","ab"]

Output: 1

Explanation:

Only "ab" appears once in each list.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result