TheRealSamuel/LeetCodeProblem
0564
1{2 "id": 2825,3 "name": "minimize_string_length",4 "difficulty": "Easy",5 "link": "https://leetcode.com/problems/minimize-string-length/",6 "date": "2023-05-28 00:00:00",7 "task_description": "Given a string `s`, you have two types of operation: Choose an index `i` in the string, and let `c` be the character in position `i`. **Delete** the **closest occurrence** of `c` to the **left** of `i` (if exists). Choose an index `i` in the string, and let `c` be the character in position `i`. **Delete** the **closest occurrence** of `c` to the **right** of `i` (if exists). Your task is to **minimize** the length of `s` by performing the above operations zero or more times. Return an integer denoting the length of the **minimized** string. **Example 1:** **Input:** s = \"aaabc\" **Output:** 3 **Explanation:** Operation 2: we choose `i = 1` so `c` is 'a', then we remove `s[2]` as it is closest 'a' character to the right of `s[1]`. `s` becomes \"aabc\" after this. Operation 1: we choose `i = 1` so `c` is 'a', then we remove `s[0]` as it is closest 'a' character to the left of `s[1]`. `s` becomes \"abc\" after this. **Example 2:** **Input:** s = \"cbbd\" **Output:** 3 **Explanation:** Operation 1: we choose `i = 2` so `c` is 'b', then we remove `s[1]` as it is closest 'b' character to the left of `s[1]`. `s` becomes \"cbd\" after this. **Example 3:** **Input:** s = \"baadccab\" **Output:** 4 **Explanation:** Operation 1: we choose `i = 6` so `c` is 'a', then we remove `s[2]` as it is closest 'a' character to the left of `s[6]`. `s` becomes \"badccab\" after this. Operation 2: we choose `i = 0` so `c` is 'b', then we remove `s[6]` as it is closest 'b' character to the right of `s[0]`. `s` becomes \"badcca\" fter this. Operation 2: we choose `i = 3` so `c` is 'c', then we remove `s[4]` as it is closest 'c' character to the right of `s[3]`. `s` becomes \"badca\" after this. Operation 1: we choose `i = 4` so `c` is 'a', then we remove `s[1]` as it is closest 'a' character to the left of `s[4]`. `s` becomes \"bdca\" after this. **Constraints:** `1 <= s.length <= 100` `s` contains only lowercase English letters",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "s = \"aaabc\"",12 "output": "3 "13 },14 {15 "label": "Example 2",16 "input": "s = \"cbbd\"",17 "output": "3 "18 },19 {20 "label": "Example 3",21 "input": "s = \"baadccab\"",22 "output": "4 "23 }24 ],25 "private_test_cases": [26 {27 "input": "tcvpsshshoempgosrmzprwdcqyjxtubmrctsxiplwhdnvnzl",28 "output": 2329 },30 {31 "input": "zbdiihopkvppoyujbpqwlazodrulomflmeektpolhnlinorgkoabhesiufhjxyouoayxffbs",32 "output": 2533 },34 {35 "input": "bfregovatvtfocylmcrvldljokensrvtuasjblfrppljuafmpanfvdvjmhijjzrevithz",36 "output": 2337 },38 {39 "input": "daokppkqwypwzrcyoxpqayzqabuxbgafmehmrmcqpowltebbzcqkgxndvblvnrxatq",40 "output": 2341 },42 {43 "input": "wqrl",44 "output": 445 },46 {47 "input": "bprwvtx",48 "output": 749 },50 {51 "input": "dvfhbqdwlneugchiwabnoirgaocunopshqpgldaxfmiihp",52 "output": 2153 },54 {55 "input": "gubdzicnxwzcufaeuuqxwxwyhmabtrbnritwhqulfdybxupchiqafwflmvqztiqdaaimqzhpwmkjek",56 "output": 2457 },58 {59 "input": "nmhzxfmnystrhyxclscmayjaxpwzndtnxdlseuyrkwmbumqrowyskalqpvsjexibbt",60 "output": 2561 },62 {63 "input": "ujkydxn",64 "output": 765 }66 ],67 "haskell_template": "minimizedStringLength :: String -> Int\nminimizedStringLength s ",68 "ocaml_template": "let minimizedStringLength (s: string) : int = ",69 "scala_template": "def minimizedStringLength(s: String): Int = { \n \n}",70 "java_template": "class Solution {\n public int minimizedStringLength(String s) {\n \n }\n}",71 "python_template": "class Solution(object):\n def minimizedStringLength(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n "72}