2981. Find Longest Special Substring That Occurs Thrice I Medium
1/**
2 * [2981] Find Longest Special Substring That Occurs Thrice I
3 *
4 * You are given a string s that consists of lowercase English letters.
5 * A string is called special if it is made up of only a single character. For example, the string "abc" is not special, whereas the strings "ddd", "zz", and "f" are special.
6 * Return the length of the longest special substring of s which occurs at least thrice, or -1 if no special substring occurs at least thrice.
7 * A substring is a contiguous non-empty sequence of characters within a string.
8 *
9 * <strong class="example">Example 1:
10 *
11 * Input: s = "aaaa"
12 * Output: 2
13 * Explanation: The longest special substring which occurs thrice is "aa": substrings "<u>aa</u>aa", "a<u>aa</u>a", and "aa<u>aa</u>".
14 * It can be shown that the maximum length achievable is 2.
15 *
16 * <strong class="example">Example 2:
17 *
18 * Input: s = "abcdef"
19 * Output: -1
20 * Explanation: There exists no special substring which occurs at least thrice. Hence return -1.
21 *
22 * <strong class="example">Example 3:
23 *
24 * Input: s = "abcaba"
25 * Output: 1
26 * Explanation: The longest special substring which occurs thrice is "a": substrings "<u>a</u>bcaba", "abc<u>a</u>ba", and "abcab<u>a</u>".
27 * It can be shown that the maximum length achievable is 1.
28 *
29 *
30 * Constraints:
31 *
32 * 3 <= s.length <= 50
33 * s consists of only lowercase English letters.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i/
39// discuss: https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn maximum_length(s: String) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2981() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.