import java.util.HashMap;
public class CommonCharacters {
public static int getCommonCharacterCount(String str1, String str2) {
HashMap<Character, Integer> charCountMap = new HashMap<>();
// Count characters in the first string
for (char ch : str1.toCharArray()) {
charCountMap.put(c, charCountMap.getOrDefault(ch, 0) + 1);
}
int commonCount = 0;
// Count common characters in the second string
for (char ch : str2.toCharArray()) {
if (charCountMap.containsKey(c) && charCountMap.get(c) > 0) {
commonCount++;
charCountMap.put(c, charCountMap.get(ch) - 1);
}
}
return commonCount;
}
public static void main(String[] args) {
String str1 = "abcdefg";
String str2 = "xayzgoe";
System.out.println("Number of common characters: " + getCommonCharacterCount(str1, str2));
}
}
/*
run:
Number of common characters: 3
*/