TheRealSamuel/LeetCodeProblem
0572
1{2 "id": 2786,3 "name": "find_the_longest_semi_repetitive_substring",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/find-the-longest-semi-repetitive-substring/",6 "date": "2023-05-27 00:00:00",7 "task_description": "You are given a digit string `s` that consists of digits from 0 to 9. A string is called **semi-repetitive** if there is **at most** one adjacent pair of the same digit. For example, `\"0010\"`, `\"002020\"`, `\"0123\"`, `\"2002\"`, and `\"54944\"` are semi-repetitive while the following are not: `\"00101022\"` (adjacent same digit pairs are 00 and 22), and `\"1101234883\"` (adjacent same digit pairs are 11 and 88). Return the length of the **longest semi-repetitive substring** of `s`. **Example 1:** **Input:** s = \"52233\" **Output:** 4 **Explanation:** The longest semi-repetitive substring is \"5223\". Picking the whole string \"52233\" has two adjacent same digit pairs 22 and 33, but at most one is allowed. **Example 2:** **Input:** s = \"5494\" **Output:** 4 **Explanation:** `s` is a semi-repetitive string. **Example 3:** **Input:** s = \"1111111\" **Output:** 2 **Explanation:** The longest semi-repetitive substring is \"11\". Picking the substring \"111\" has two adjacent same digit pairs, but at most one is allowed. **Constraints:** `1 <= s.length <= 50` `'0' <= s[i] <= '9'`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "s = \"52233\"",12 "output": "4 "13 },14 {15 "label": "Example 2",16 "input": "s = \"5494\"",17 "output": "4 "18 },19 {20 "label": "Example 3",21 "input": "s = \"1111111\"",22 "output": "2 "23 }24 ],25 "private_test_cases": [26 {27 "input": "800224406092326904284192442626098218931287187431",28 "output": 4229 },30 {31 "input": "82069083341368866002193339400441",32 "output": 1433 },34 {35 "input": "5025542296885025828",36 "output": 1237 },38 {39 "input": "4530164565084030141690",40 "output": 2241 },42 {43 "input": "7192337667651626882611322",44 "output": 1345 },46 {47 "input": "8027412881409430111445840735378988310",48 "output": 1749 },50 {51 "input": "135433309636053",52 "output": 1053 },54 {55 "input": "378129559558437",56 "output": 1057 },58 {59 "input": "3820",60 "output": 461 },62 {63 "input": "36873498932897249729768516",64 "output": 2665 }66 ],67 "haskell_template": "longestSemiRepetitiveSubstring :: String -> Int\nlongestSemiRepetitiveSubstring s ",68 "ocaml_template": "let longestSemiRepetitiveSubstring (s: string) : int = ",69 "scala_template": "def longestSemiRepetitiveSubstring(s: String): Int = { \n \n}",70 "java_template": "class Solution {\n public int longestSemiRepetitiveSubstring(String s) {\n \n }\n}",71 "python_template": "class Solution(object):\n def longestSemiRepetitiveSubstring(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n "72}