base_words and goal_words. No word contains a repeated letter.
A word from goal_words is reachable if it can be made from some word in base_words like this:
1. append one lowercase English letter that the word does not already contain;
2. rearrange the letters of the result in any order (keeping the order as it is also counts).
The lists themselves never change: each word in goal_words is checked on its own. Return how many words in goal_words are reachable.base_words=["rat", "pen", "lo"], goal_words=["tarp", "pen", "owl", "open"] → 3
"tarp" is "rat" plus p, "owl" is "lo" plus w, and "open" is "pen" plus o, with letters rearranged. "pen" is already a base word, but a letter must be added, so it does not count. The answer is 3.
base_words=["ab"], goal_words=["abcd", "b", "bca"] → 1
"abcd" is two letters longer and "b" is shorter. Only "bca" works. The answer is 1.
base_words=["x", "yz"], goal_words=["zy", "xyz", "wx"] → 2
base_words=["rat", "pen", "lo"], goal_words=["tarp", "pen", "owl", "open"]
3
Run checks the first 3 tests in your browser. Submit checks all 49 tests on the server, hidden ones included.