Nice video! You could also add up the anagramPairs in the hashMap checking, this way it gets rid of the explicit combination calculation. if (hashMap.containsKey(k)) { anagramPairs += hashMap.get(k); hashMap.put(k, hashMap.get(k) + 1); } else { hashMap.put(k, 1); }
This is really nice. It works because we are sorting the strings before putting in the hashmap. So if "aab" is already there in hashmap lets say with frequency 1. If the next substring is "aba", Sorting makes it aab and as "aab" is already there in the hashmap, we simply increase the anagramPairs value because we have found a matching pair as "aab" and "aba" are anagrams. Later we increase the count in the hashmap for the next substrings. Say, "baa".
Nice video! You could also add up the anagramPairs in the hashMap checking, this way it gets rid of the explicit combination calculation.
if (hashMap.containsKey(k)) {
anagramPairs += hashMap.get(k);
hashMap.put(k, hashMap.get(k) + 1);
} else {
hashMap.put(k, 1);
}
Thanks!
This is really nice. It works because we are sorting the strings before putting in the hashmap. So if "aab" is already there in hashmap lets say with frequency 1. If the next substring is "aba", Sorting makes it aab and as "aab" is already there in the hashmap, we simply increase the anagramPairs value because we have found a matching pair as "aab" and "aba" are anagrams. Later we increase the count in the hashmap for the next substrings. Say, "baa".
Amazing insight with the combinatorial formula, was stuck on this!
Thank you for your explanation! Your combination formula explanation helped me a lot! Thanks again!
Very Good Solution!!! Thank you !!!!!
Glad it helped!
Thanks for the solution in java.
I searched a lot this sol in java but I got here thanks man
Awesome you found it and it helped Santhosh!
How did you come up with the formula... i got as far as comparing the strings.. but couldnt figure out the forumla?
@A lqbal this is the good doc en.wikipedia.org/wiki/Combination to get you the idea of it
this is a much better explaination: www.mathsisfun.com/combinatorics/combinations-permutations.html
Nice brother
Thanks. Glad it's helpful!
@@edvinhe2603 very helpful for me
@@edvinhe2603 thanks lot
You can start with j = i+1 in the loop instead of j = 0. Anyways nice explanation.
That's right. And finally i've changed it to j=i in the video to let the test cases pass.
why are you speaking too low in this video ?
Because he is not an English man. I like how he speaks.