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

&nbsp;
Example 1:

Input: words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]
Output: 2
Explanation:
- "leetcode" appears exactly once in each of the two arrays. We count this string.
- "amazing" appears exactly once in each of the two arrays. We count this string.
- "is" appears in each of the two arrays, but there are 2 occurrences of it in words1. We do not count this string.
- "as" appears once in words1, but does not appear in words2. We do not count this string.
Thus, there are 2 strings that appear exactly once in each of the two arrays.


Example 2:

Input: words1 = ["b","bb","bbb"], words2 = ["a","aa","aaa"]
Output: 0
Explanation: There are no strings that appear in each of the two arrays.


Example 3:

Input: words1 = ["a","ab"], words2 = ["a","a","a","ab"]
Output: 1
Explanation: The only string that appears exactly once in each of the two arrays is "ab".


&nbsp;
Constraints:


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


class Solution:
	def countWords(self, words1: List[str], words2: List[str]) -> int:
		count = Counter(words1 + words2)
		return len([word for word in count if count[word] == 2 and word in words1 and word in words2])
class Solution
{
    public int countWords(String[] words1, String[] words2)
    {
        HashMap<String, Integer> map1 = new HashMap<>();
        HashMap<String, Integer> map2 = new HashMap<>();
		
        for(String word : words1)
            map1.put(word,map1.getOrDefault(word,0)+1);
        for(String word : words2)
            map2.put(word,map2.getOrDefault(word,0)+1);
			
        int count = 0;
        for(String word : words1)
            if(map1.get(word) == 1 && map2.getOrDefault(word,0) == 1)
                count++;
        return count;
    }
}
class Solution {
public:
    int countWords(vector<string>& words1, vector<string>& words2) {
        unordered_map<string, int> freq1, freq2;
        for (auto& s : words1) ++freq1[s];
        for (auto& s : words2) ++freq2[s];
        int ans = 0;
        for (auto& [s, v] : freq1)
            if (v == 1 && freq2[s] == 1) ++ans;
        return ans;
    }
};
var countWords = function(words1, words2) {
    const map1 = new Map();
    const map2 = new Map();
    let count = 0;

    for (const word of words1) {
        map1.set(word, map1.get(word) + 1 || 1);
    }
    for (const word of words2) {
        map2.set(word, map2.get(word) + 1 || 1);
    }
    for (const word of words1) {
        if (map1.get(word) === 1 && map2.get(word) === 1) count++;
    }

    return count;
};
Count Common Words With One Occurrence