FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 2510,3 "name": "maximum-deletions-on-a-string",4 "difficulty": "Hard",5 "link": "https://leetcode.com/problems/maximum-deletions-on-a-string/",6 "date": "2022-09-25",7 "task_description": "You are given a string `s` consisting of only lowercase English letters. In one operation, you can: Delete **the entire string** `s`, or Delete the **first** `i` letters of `s` if the first `i` letters of `s` are **equal** to the following `i` letters in `s`, for any `i` in the range `1 <= i <= s.length / 2`. For example, if `s = \"ababc\"`, then in one operation, you could delete the first two letters of `s` to get `\"abc\"`, since the first two letters of `s` and the following two letters of `s` are both equal to `\"ab\"`. Return _the **maximum** number of operations needed to delete all of _`s`. **Example 1:** ``` **Input:** s = \"abcabcdabc\" **Output:** 2 **Explanation:** - Delete the first 3 letters (\"abc\") since the next 3 letters are equal. Now, s = \"abcdabc\". - Delete all the letters. We used 2 operations so return 2. It can be proven that 2 is the maximum number of operations needed. Note that in the second operation we cannot delete \"abc\" again because the next occurrence of \"abc\" does not happen in the next 3 letters. ``` **Example 2:** ``` **Input:** s = \"aaabaab\" **Output:** 4 **Explanation:** - Delete the first letter (\"a\") since the next letter is equal. Now, s = \"aabaab\". - Delete the first 3 letters (\"aab\") since the next 3 letters are equal. Now, s = \"aab\". - Delete the first letter (\"a\") since the next letter is equal. Now, s = \"ab\". - Delete all the letters. We used 4 operations so return 4. It can be proven that 4 is the maximum number of operations needed. ``` **Example 3:** ``` **Input:** s = \"aaaaa\" **Output:** 5 **Explanation:** In each operation, we can delete the first letter of s. ``` **Constraints:** `1 <= s.length <= 4000` `s` consists only of lowercase English letters.",8 "test_case": [9 {10 "label": "Example 1",11 "input": "s = \"abcabcdabc\"",12 "output": "2 "13 },14 {15 "label": "Example 2",16 "input": "s = \"aaabaab\"",17 "output": "4 "18 },19 {20 "label": "Example 3",21 "input": "s = \"aaaaa\"",22 "output": "5 "23 }24 ],25 "constraints": [26 "Delete the entire string s, or",27 "Delete the first i letters of s if the first i letters of s are equal to the following i letters in s, for any i in the range 1 <= i <= s.length / 2.",28 "1 <= s.length <= 4000",29 "s consists only of lowercase English letters."30 ],31 "python_template": "class Solution(object):\n def deleteString(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n ",32 "java_template": "class Solution {\n public int deleteString(String s) {\n \n }\n}",33 "metadata": {34 "func_name": "deleteString"35 }36}