TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 2256,3 "name": "count_words_obtained_after_adding_a_letter",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/count-words-obtained-after-adding-a-letter/",6 "date": "1641081600000",7 "task_description": "You are given two **0-indexed** arrays of strings `startWords` and `targetWords`. Each string consists of **lowercase English letters** only. For each string in `targetWords`, check if it is possible to choose a string from `startWords` and perform a **conversion operation** on it to be equal to that from `targetWords`. The **conversion operation** is described in the following two steps: **Append** any lowercase letter that is **not present** in the string to its end. For example, if the string is `\"abc\"`, the letters `'d'`, `'e'`, or `'y'` can be added to it, but not `'a'`. If `'d'` is added, the resulting string will be `\"abcd\"`. **Rearrange** the letters of the new string in **any** arbitrary order. For example, `\"abcd\"` can be rearranged to `\"acbd\"`, `\"bacd\"`, `\"cbda\"`, and so on. Note that it can also be rearranged to `\"abcd\"` itself. Return _the **number of strings** in _`targetWords`_ that can be obtained by performing the operations on **any** string of _`startWords`. **Note** that you will only be verifying if the string in `targetWords` can be obtained from a string in `startWords` by performing the operations. The strings in `startWords` **do not** actually change during this process. **Example 1:** ``` **Input:** startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"] **Output:** 2 **Explanation:** - In order to form targetWords[0] = \"tack\", we use startWords[1] = \"act\", append 'k' to it, and rearrange \"actk\" to \"tack\". - There is no string in startWords that can be used to obtain targetWords[1] = \"act\". Note that \"act\" does exist in startWords, but we **must** append one letter to the string before rearranging it. - In order to form targetWords[2] = \"acti\", we use startWords[1] = \"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 targetWords[0] = \"abc\", we use startWords[0] = \"ab\", add 'c' to it, and rearrange it to \"abc\". - There is no string in startWords that can be used to obtain targetWords[1] = \"abcd\". ``` **Constraints:** `1 <= startWords.length, targetWords.length <= 5 * 104` `1 <= startWords[i].length, targetWords[j].length <= 26` Each string of `startWords` and `targetWords` consists of lowercase English letters only. No letter occurs more than once in any string of `startWords` or `targetWords`.",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "startWords = [\"ant\",\"act\",\"tack\"], targetWords = [\"tack\",\"act\",\"acti\"]",12 "output": "2 "13 },14 {15 "label": "Example 2",16 "input": "startWords = [\"ab\",\"a\"], targetWords = [\"abc\",\"abcd\"]",17 "output": "1 "18 }19 ],20 "private_test_cases": [],21 "haskell_template": "wordCount :: [String] -> [String] -> Int\nwordCount startWords targetWords ",22 "ocaml_template": "let wordCount (startWords: string list) (targetWords: string list) : int = ",23 "scala_template": "def wordCount(startWords: List[String],targetWords: List[String]): Int = { \n \n}",24 "java_template": "public static int wordCount(List<String> startWords, List<String> targetWords) {\n\n}",25 "python_template": "class Solution(object):\n def wordCount(self, startWords, targetWords):\n \"\"\"\n :type startWords: List[str]\n :type targetWords: List[str]\n :rtype: int\n \"\"\"\n "26}