AI-enabled coding: find words that can be formed using a subset of the given characters (backtracking)
Asked in the AI-enabled coding stage. Author used backtracking; a commenter suggested trie.
Implement find_words(characters, words). characters is a string, and words is an array of distinct strings. Return the words that can be formed by rearranging any non-empty subset of characters, using each character no more often than it appears in characters. Preserve the order from words.
def find_words(characters, words):