Dictionary Words Formable From Letters
Problem statement
Given a lowercase dictionary dictionary and a lowercase string letters, return every dictionary word that can be built from the available letters.
Each occurrence in letters may be used at most once per word. Preserve dictionary order, preserve repeated dictionary entries, and return an empty array when no word is buildable. The empty word is buildable from any letter multiset.
Function
wordsFromLetters(dictionary: String[], letters: String) → String[]Examples
Example 1
dictionary = ["cat","act","taco","dog"]letters = "tac"return = ["cat","act"]Both cat and act use exactly the three available letters. taco needs an extra letter and dog uses unavailable letters.
Example 2
dictionary = ["a","aa","aaa"]letters = "aa"return = ["a","aa"]The two available copies of a can build the first two words but not the third.
Example 3
dictionary = []letters = "abc"return = []An empty dictionary contains no words to return.
Constraints
0 <= dictionary.length <= 100000.0 <= dictionary[i].length,letters.length <= 100000.- The total length of all dictionary words is at most
1000000. - All strings contain only lowercase English letters.