FPEvalRepoPublic/LeetCodeMetaData
0402
1{2 "id": 3451,3 "name": "string-compression-iii",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/string-compression-iii/",6 "date": "2024-05-19",7 "task_description": "Given a string `word`, compress it using the following algorithm: Begin with an empty string `comp`. While `word` is **not** empty, use the following operation: Remove a maximum length prefix of `word` made of a _single character_ `c` repeating **at most** 9 times. Append the length of the prefix followed by `c` to `comp`. Return the string `comp`. **Example 1:** **Input:** word = \"abcde\" **Output:** \"1a1b1c1d1e\" **Explanation:** Initially, `comp = \"\"`. Apply the operation 5 times, choosing `\"a\"`, `\"b\"`, `\"c\"`, `\"d\"`, and `\"e\"` as the prefix in each operation. For each prefix, append `\"1\"` followed by the character to `comp`. **Example 2:** **Input:** word = \"aaaaaaaaaaaaaabb\" **Output:** \"9a5a2b\" **Explanation:** Initially, `comp = \"\"`. Apply the operation 3 times, choosing `\"aaaaaaaaa\"`, `\"aaaaa\"`, and `\"bb\"` as the prefix in each operation. For prefix `\"aaaaaaaaa\"`, append `\"9\"` followed by `\"a\"` to `comp`. For prefix `\"aaaaa\"`, append `\"5\"` followed by `\"a\"` to `comp`. For prefix `\"bb\"`, append `\"2\"` followed by `\"b\"` to `comp`. **Constraints:** `1 <= word.length <= 2 * 105` `word` consists only of lowercase English letters.",8 "test_case": [9 {10 "label": "Example 1",11 "input": "word = \"abcde\"",12 "output": "\"1a1b1c1d1e\" "13 },14 {15 "label": "Example 2",16 "input": "word = \"aaaaaaaaaaaaaabb\"",17 "output": "\"9a5a2b\" "18 }19 ],20 "constraints": [21 "Begin with an empty string comp. While word is not empty, use the following operation:\n\n\t\nRemove a maximum length prefix of word made of a single character c repeating at most 9 times.\nAppend the length of the prefix followed by c to comp.",22 "Remove a maximum length prefix of word made of a single character c repeating at most 9 times.",23 "Append the length of the prefix followed by c to comp.",24 "Remove a maximum length prefix of word made of a single character c repeating at most 9 times.",25 "Append the length of the prefix followed by c to comp.",26 "For prefix \"aaaaaaaaa\", append \"9\" followed by \"a\" to comp.",27 "For prefix \"aaaaa\", append \"5\" followed by \"a\" to comp.",28 "For prefix \"bb\", append \"2\" followed by \"b\" to comp.",29 "1 <= word.length <= 2 * 105",30 "word consists only of lowercase English letters."31 ],32 "python_template": "class Solution(object):\n def compressedString(self, word):\n \"\"\"\n :type word: str\n :rtype: str\n \"\"\"\n ",33 "java_template": "class Solution {\n public String compressedString(String word) {\n \n }\n}",34 "metadata": {35 "func_name": "compressedString"36 }37}