Class Solution
-
- All Implemented Interfaces:
public final class Solution2135 - Count Words Obtained After Adding a Letter\.
Medium
You are given two 0-indexed arrays of strings
startWordsandtargetWords. Each string consists of lowercase English letters only.For each string in
targetWords, check if it is possible to choose a string fromstartWordsand perform a conversion operation on it to be equal to that fromtargetWords.The conversion operation is described in the following two steps:
Append any lowercase letter that is not present in the string to its end.
Rearrange the letters of the new string in any arbitrary order.
Return the number of strings in
targetWordsthat can be obtained by performing the operations on any string ofstartWords.Note that you will only be verifying if the string in
targetWordscan be obtained from a string instartWordsby performing the operations. The strings instartWordsdo not actually change during this process.Example 1:
Input: startWords = "ant","act","tack", targetWords = "tack","act","acti"
Output: 2
Explanation:
In order to form targetWords0 = "tack", we use startWords1 = "act", append 'k' to it, and rearrange "actk" to "tack".
There is no string in startWords that can be used to obtain targetWords1 = "act".
Note that "act" does exist in startWords, but we must append one letter to the string before rearranging it.
In order to form targetWords2 = "acti", we use startWords1 = "act", append 'i' to it, and rearrange "acti" to "acti" itself.
Example 2:
Input: startWords = "ab","a", targetWords = "abc","abcd"
Output: 1
Explanation:
In order to form targetWords0 = "abc", we use startWords0 = "ab", add 'c' to it, and rearrange it to "abc".
There is no string in startWords that can be used to obtain targetWords1 = "abcd".
Constraints:
<code>1 <= startWords.length, targetWords.length <= 5 * 10<sup>4</sup></code>
1 <= startWords[i].length, targetWords[j].length <= 26Each string of
startWordsandtargetWordsconsists of lowercase English letters only.No letter occurs more than once in any string of
startWordsortargetWords.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-