Skip to content

Commit ceb8443

Browse files
committed
Dec 10
1 parent 631ff8f commit ceb8443

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from collections import defaultdict
2+
3+
4+
class Solution:
5+
def maximumLength(self, s: str) -> int:
6+
freq = defaultdict(int)
7+
for i in range(len(s)):
8+
length = 1
9+
freq[(s[i], length)] += 1
10+
for j in range(i, len(s)-1):
11+
if s[j] == s[j+1]:
12+
length += 1
13+
freq[(s[i], length)] += 1
14+
else:
15+
break
16+
17+
max_length = -1
18+
for key, value in freq.items():
19+
if value >= 3:
20+
max_length = max(max_length, key[1])
21+
return max_length
22+
23+
24+
def main():
25+
s = 'aaaa'
26+
assert Solution().maximumLength(s) == 2
27+
28+
s = 'abcdef'
29+
assert Solution().maximumLength(s) == -1
30+
31+
s = 'abcaba'
32+
assert Solution().maximumLength(s) == 1
33+
34+
35+
if __name__ == '__main__':
36+
main()

2024-12-December-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| December 7 | [1760. Minimum Limit of Balls in a Bag](https://leetcode.com/problems/minimum-limit-of-balls-in-a-bag/) | Medium | Solved |
1313
| December 8 | [2054. Two Best Non-Overlapping Events](https://leetcode.com/problems/two-best-non-overlapping-events/) | Medium | Solved |
1414
| December 9 | [3152. Special Array II](https://leetcode.com/problems/special-array-ii/) | Medium | Solved |
15-
| December 10 | []() | | |
15+
| December 10 | [2981. Find Longest Special Substring That Occurs Thrice I](https://leetcode.com/problems/find-longest-special-substring-that-occurs-thrice-i/) | Medium | Unsolved |
1616
| December 11 | []() | | |
1717
| December 12 | []() | | |
1818
| December 13 | []() | | |
@@ -39,5 +39,5 @@
3939
| Level | Problems | Solved | Unsolved |
4040
| --- | --- | --- | --- |
4141
| Easy | 2 | 2 | 0 |
42-
| Medium | 7 | 6 | 1 |
42+
| Medium | 8 | 6 | 2 |
4343
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)