Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to get a list of all words that are anagrams of all substrings (scrabble)?

Tags:

People also ask

How can we use hash table to find all anagrams in a dictionary?

A simple method is to create a Hash Table. Calculate the hash value of each word in such a way that all anagrams have the same hash value. Populate the Hash Table with these hash values. Finally, print those words together with the same hash values.

How do you find the number of anagrams in a string?

Once occurrence 'o' of each frequency array is stored, total anagrams will be the sum of o*(o-1)/2 for all different frequency arrays because if a particular substring has 'o' anagrams in string total o*(o-1)/2 anagram pairs can be formed.

What is anagram substring?

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. Example 1: Input: s = "cbaebabacd", p = "abc" Output: [0,6] Explanation: The substring with start index = 0 is "cba", which is an anagram of "abc".


Eg if input string is helloworld I want the output to be like:

do
he
we
low
hell
hold
roll
well
word
hello
lower
world
...

all the way up to the longest word that is an anagram of a substring of helloworld. Like in Scrabble for example. The input string can be any length, but rarely more than 16 chars.

I've done a search and come up with structures like a trie, but I am still unsure of how to actually do this.