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.
- Strings: Making Anagrams
- Discussions
Strings: Making Anagrams
Strings: Making Anagrams
+ 0 comments def makeAnagram(a, b): # Write your code here a_counts = Counter(a) b_counts = Counter(b) char_set = set(a + b) deletions = 0 for char in char_set: deletions += abs(a_counts.get(char, 0) - b_counts.get(char, 0)) return deletions
+ 0 comments Clear Python solution
def makeAnagram(a, b): remove_count = 0 a_set = set(a) b_set = set(b) a_count_map = {el: a.count(el) for el in a_set} b_count_map = {el: b.count(el) for el in b_set} for el in a_set: if a_count_map.get(el, 0) > b_count_map.get(el, 0): remove_count += a_count_map.get(el, 0) - b_count_map.get(el, 0) for el in b_set: if b_count_map.get(el, 0) > a_count_map.get(el, 0): remove_count += b_count_map.get(el, 0) - a_count_map.get(el, 0) return remove_count
+ 0 comments def makeAnagram(a, b):
# Write your code here d={} x=set(a) & set(b) l=list(x) for i in l: d[i]=a.count(i)+b.count(i)-(abs(a.count(i)-b.count(i))) return (len(a)+len(b)-sum(d.values()))
+ 0 comments public static int[] rep(String s){ String alpha="abcdefghijklmnopqrstuvwxyz";
int [] arr=new int [26];www.edmondpaintingpros.com
for(int i=0;i
+ 0 comments C++ Solution
int makeAnagram(string a, string b) { string anagram; for (int i = 0; i < a.length(); i++) { int bCharCount = (int)count(b.begin(), b.end(), a.at(i)); int anagramCount = (int)count(anagram.begin(), anagram.end(), a.at(i)); if ((b.find(a[i]) != string::npos)) { if (anagramCount < bCharCount) anagram += a[i]; } } return (a.length() + b.length()) - (anagram.length() * 2); }
Load more conversations
Sort 2108 Discussions, By:
Please Login in order to post a comment