I am looking for an efficient algorithm to do the following.
Given a table/dictionary of letter counts
counts = {'a': 3, 'b': 2, 'd': 2, 'e': 2, 'k':2, 'r': 2 }
and a list of M words
words = ['break, 'add', 'build' ... ]
write a function that finds N words using all the letters (and words from the list)
>>> find_words(counts, words, 3)
['break', 'break', 'add']
The naive approach of going over all the words N times is too slow (I think it's O(m^n)).