HackerRank - Making Anagrams | Full Solution with Simplified Examples and Visuals | Study Algorithms

preview_player
Показать описание
Two Strings are said to be anagrams if they have the exact same characters and their frequency. In this problem you are given two strings, and you need to determine the minimum number of characters to be deleted, so that they become anagrams. Watch the video to understand the problem correctly and work with me to find an efficient solution. All along with visuals and explanations.

Chapters:
00:00 - Intro
00:58 - Problem statement and description
02:58 - Brute Force Solution
05:03 - Efficient Solution
09:20 - Dry-run of code
11:28 - Final Thoughts

📚 Links to topics I talk about in the video:

📖 Reference Books:

🎥 My Recording Gear:

💻 Get Social 💻

#hackerrank #programming #interview
Рекомендации по теме
Комментарии
Автор

You make it Simple, In this World their are very few people who make things easy You are one of them,

harshsahu
Автор

what if s1 is modified to "raet" (changing the 't' to the end) and s2 remains as "tars"? you array will store the same data as you showed in your example but actually the answer should be 4 because "ra" is the anagram in that case. I think in this exercise the order matters, am I wrong?

milgercf
Автор

Concept is clear with the video, please explain the program itself as well, why you are taking int c array or like thi

BabyKrishna
Автор

I am able to solve problems because of you

deepika
Автор

your explanation is crystal clear..thank you so much bro..

vikrantkambli
Автор

Hae bro
Can u explain
What is Math.abs(i)

rajakabdul
Автор

Very detailed explanation. Thank you for your time and insight.

Philthyyy
Автор

Hi. Just a question here, why are doing (s1.char(i) - 'a' ) here? what is the significance of 'a'. Thanks

taherkp
Автор

int n1{s1.size()};
int n2{s2.size()};
int result{};
vector<char> sr1(26);
vector<char> sr2(26);

for(int i=0; i < n1; ++i)
{
sr1[abs('a'-s1[i])] +=1;
}

for(int i=0; i < n2; ++i)
{
sr2[abs('a'-s2[i])] +=1;
}


for(int i = 0; i < 26; ++i)
{
result += abs(sr2[i]-sr1[i]);

}
return result;



why it's incorrect?

rmukeshverma
Автор

int makeAnagram(string a, string b) {
int *c = new int(26);
for(int i=0;i<a.length();i++){
c[a.at(i) - 'a']++;
}
for(int i =0; i<b.length();i++){
c[b.at(i) - 'a']--;
}
int total = 0;
for(int i =0;i<26;i++){
total = total + abs(i);
}

return total;
}

I have written this code here in c++, but not getting the Right o/p???

pratyakshamaheshwari
Автор

HashMap<Character, Integer> hm= new HashMap<>();
for(int i=0; i<s1.length(); i++){

hm.put(s1.charAt(i), 1);
}else{
hm.put(s1.charAt(i), hm.get(s1.charAt(i))+1);
}
}
int ans=0;

for(int i=0; i<s2.length(); i++){

if(hm.get(s2.charAt(i))==0){
hm.remove(s2.charAt(i));
ans++;
}else{
hm.put(s2.charAt(i), hm.get(s2.charAt(i))-1);
}

}else{
ans++;
}
}

for(Character ch:hm.keySet()){
ans=ans+hm.get(ch);
}
return ans;

MohdAshraf-nwbz
welcome to shbcf.ru