You are given two arrays of strings: words1 and words2.
A word is considered valid if:
It appears exactly once in words1, and
It appears exactly once in words2.
Your task is to count how many words satisfy both conditions.
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
Input: words1 = ["b","bb","bbb"] words2 = ["a","aa","aaa"]
Output: 0
Explanation:
No word appears in both arrays → result is 0
Input: words1 = ["a","ab"] words2 = ["a","a","a","ab"]
Output: 1
Explanation:
Only "ab" appears once in each list.
Accepted:
Submission: