Count Common Words With One Occurrence

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Given two string arrays words1 and words2, return the number of strings that appear exactly once in each of the two arrays.
LeetCode Problem - 2085
class Solution {
public int countWords(String[] words1, String[] words2) {
// Variable to store the count of words appearing exactly once in both arrays
int result = 0;
// HashMap to store the frequency of words in words1
HashMap<String, Integer> hm1 = new HashMap<>();
// HashMap to store the frequency of words in words2
HashMap<String, Integer> hm2 = new HashMap<>();
// Count the frequency of words in words1
for (String str : words1) {
hm1.put(str, hm1.getOrDefault(str, 0) + 1);
}
// Count the frequency of words in words2
for (String str : words2) {
hm2.put(str, hm2.getOrDefault(str, 0) + 1);
}
// Iterate through each word in words1
for (String word : words1) {
// If the word appears exactly once in both words1 and words2, increment the result
if (hm1.get(word) == 1 && hm2.getOrDefault(word, 0) == 1) {
result++;
}
}
// Return the count of words appearing exactly once in both arrays
return result;
}
}




