Count Words Obtained After Adding a Letter
specialist · 980 · lc medium +32 · verified · 43.9% accepted · 725 likes · top 26%
Description
You are given two 0-indexed arrays of strings startWords and targetWords, each consisting of lowercase English letters only.
For each string in targetWords, determine whether it can be produced from some string in startWords by applying the following two-step conversion:
- Append one lowercase letter that does not already appear in the string.
- For example, if the string is "abc", you could add 'd', 'e', or 'y', but not 'a'. Adding 'd' gives "abcd".
- Rearrange all the letters in any order.
- For example, "abcd" can be rearranged to "acbd", "bacd", "cbda", etc.
Return the number of strings in targetWords that can be obtained this way.
Note that the strings in startWords are not actually modified during this process.
Example 1:
Example 2:
Code