Make it Anagram | Lei Jiang Coding
Alice recently started learning about cryptography and found that anagrams are very useful. Two strings are anagrams of each other if they have same character set. For example strings
Alice decides on an encryption scheme involving 2 large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. She need your help in finding out this number.
Given two strings (they can be of same or different length) help her in finding out the minimum number of character deletions required to make two strings anagrams. Any characters can be deleted from any of the strings.
Read full article from Make it Anagram | Lei Jiang Coding
Alice recently started learning about cryptography and found that anagrams are very useful. Two strings are anagrams of each other if they have same character set. For example strings
"bacdc"
and "dcbac"
are anagrams, while strings "bacdc"
and "dcbad"
are not.Alice decides on an encryption scheme involving 2 large strings where encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. She need your help in finding out this number.
Given two strings (they can be of same or different length) help her in finding out the minimum number of character deletions required to make two strings anagrams. Any characters can be deleted from any of the strings.
int
Anagram(string s1, string s2){
int
map[N] = {0};
for
(
int
i = 0; i < s1.size(); ++i){
map[s1[i] -
'a'
]++;
}
for
(
int
i = 0; i < s2.size(); ++i){
map[s2[i] -
'a'
]--;
}
int
count = 0;
for
(
int
i = 0; i < N; ++i){
if
(map[i] > 0)
count += map[i];
else
if
(map[i] < 0)
count +=
abs
(map[i]);
}
return
count;
}