FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 2854,3 "name": "decremental-string-concatenation",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/decremental-string-concatenation/",6 "date": "2023-06-10",7 "task_description": "You are given a **0-indexed** array `words` containing `n` strings. Let's define a **join** operation `join(x, y)` between two strings `x` and `y` as concatenating them into `xy`. However, if the last character of `x` is equal to the first character of `y`, one of them is **deleted**. For example `join(\"ab\", \"ba\") = \"aba\"` and `join(\"ab\", \"cde\") = \"abcde\"`. You are to perform `n - 1` **join** operations. Let `str0 = words[0]`. Starting from `i = 1` up to `i = n - 1`, for the `ith` operation, you can do one of the following: Make `stri = join(stri - 1, words[i])` Make `stri = join(words[i], stri - 1)` Your task is to **minimize** the length of `strn - 1`. Return _an integer denoting the minimum possible length of_ `strn - 1`. **Example 1:** ``` **Input:** words = [\"aa\",\"ab\",\"bc\"] **Output:** 4 **Explanation: **In this example, we can perform join operations in the following order to minimize the length of str2: str0 = \"aa\" str1 = join(str0, \"ab\") = \"aab\" str2 = join(str1, \"bc\") = \"aabc\" It can be shown that the minimum possible length of str2 is 4. ``` **Example 2:** ``` **Input:** words = [\"ab\",\"b\"] **Output:** 2 **Explanation:** In this example, str0 = \"ab\", there are two ways to get str1: join(str0, \"b\") = \"ab\" or join(\"b\", str0) = \"bab\". The first string, \"ab\", has the minimum length. Hence, the answer is 2. ``` **Example 3:** ``` **Input:** words = [\"aaa\",\"c\",\"aba\"] **Output:** 6 **Explanation:** In this example, we can perform join operations in the following order to minimize the length of str2: str0 = \"aaa\" str1 = join(str0, \"c\") = \"aaac\" str2 = join(\"aba\", str1) = \"abaaac\" It can be shown that the minimum possible length of str2 is 6. ``` **Constraints:** `1 <= words.length <= 1000` `1 <= words[i].length <= 50` Each character in `words[i]` is an English lowercase letter",8 "test_case": [9 {10 "label": "Example 1",11 "input": "words = [\"aa\",\"ab\",\"bc\"]",12 "output": "4 "13 },14 {15 "label": "Example 2",16 "input": "words = [\"ab\",\"b\"]",17 "output": "2 "18 },19 {20 "label": "Example 3",21 "input": "words = [\"aaa\",\"c\",\"aba\"]",22 "output": "6 "23 }24 ],25 "constraints": [26 "Make stri = join(stri - 1, words[i])",27 "Make stri = join(words[i], stri - 1)",28 "1 <= words.length <= 1000",29 "1 <= words[i].length <= 50",30 "Each character in words[i] is an English lowercase letter"31 ],32 "python_template": "class Solution(object):\n def minimizeConcatenatedLength(self, words):\n \"\"\"\n :type words: List[str]\n :rtype: int\n \"\"\"\n ",33 "java_template": "class Solution {\n public int minimizeConcatenatedLength(String[] words) {\n \n }\n}",34 "metadata": {35 "func_name": "minimizeConcatenatedLength"36 }37}