You are provided with:
wordSet, containing n elements.sentences, containing m elements. Each sentence is a string composed of space-separated words, and every word consists solely of lowercase English letters.Two words are defined as anagrams when they share the exact same characters with identical frequencies, possibly arranged in a different order. For any given sentence, you may replace any word with another word from wordSet that is an anagram of it. If a word in the sentence has no anagram present in wordSet (the word itself does not count unless it appears in wordSet), then no valid sentence can be constructed, and the count for that sentence is 0.
Your goal is to return an array result of length m, where result[i] equals the total number of distinct sentences that can be formed from sentences[i].
Constraints:
0 ≤ wordSet.length ≤ 10^41 ≤ sentences.length ≤ 10^31 ≤ wordSet[i].length ≤ 20Example 1:
wordSet = ["listen", "silent", "it", "is"], sentences = ["listen it is silent"]
[4]
The 4 possible sentences are: "listen it is listen" "listen it is silent" "silent it is listen" "silent it is silent"
Example 2:
wordSet = ["ab", "ba", "cd"], sentences = ["ab ef"]
[0]
Example 3:
wordSet = ["ab", "ba", "abc", "bca", "cab", "de", "ed"], sentences = ["ab abc de abc", "ba cab ed ab", "cab ed ab ba", "abc abc abc", "ab de", "abc ba de", "xy ab"]
[36, 24, 24, 27, 4, 12, 0]
Example 1
Input:
4
listen
silent
it
is
1
listen it is silent
Output: 4
Example 2
Input:
3
ab
ba
cd
1
ab ef
Output: 0