- Technique 3 Use The Fact That An Anagrams Have The Same Number Sum Of Distinct Of Letters In Each Word Given That Wr 1 (70.75 KiB) Viewed 60 times
Technique #3: Use the fact that an anagrams have the same number sum of distinct of letters in each word. Given that, wr
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Technique #3: Use the fact that an anagrams have the same number sum of distinct of letters in each word. Given that, wr
Technique #3: Use the fact that an anagrams have the same number sum of distinct of letters in each word. Given that, write an algorithm to compare if two words are anagrams of each other by comparing the sum of distinct letters. So, for anagrams Stressed Desserts the sum for each charecter is: = d = 1 e = 2 r = 1 s = 3 words that are anagrams of eachother have the same sum for each distinct character. hint: you can use an array to hold the sums of individual characters then index into the sum using the ascii value of a character. Using the example above of "Stressed" we know the asci value for 'd' is 100. So to increment the amount of d's we observe in an array we can do A[100] = +1; or A[asci(d)] = +1;