We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Well for this one Very simple solution is to add the Char count in hasmap and remove which is there on the first one.
public static int makeAnagram(String a, String b) {
// Write your code here
int deletecount = 0;
HashMap<Character,Integer> checkFreq = new HashMap<>();
for (char c : a.toCharArray()) {
checkFreq.put(c, checkFreq.getOrDefault(c, 0) + 1);
}
// Subtract frequency using second string
for (char c : b.toCharArray()) {
checkFreq.put(c, checkFreq.getOrDefault(c, 0) - 1);
}
for(int count : checkFreq.values()){
deletecount += Math.abs(count);
}
return deletecount;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
Well for this one Very simple solution is to add the Char count in hasmap and remove which is there on the first one.