Skip to content

Commit 7d1dc3d

Browse files
committed
Jun 10
1 parent 42e3671 commit 7d1dc3d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from collections import Counter
2+
3+
4+
class Solution:
5+
def maxDifference(self, s: str) -> int:
6+
freq = Counter(s)
7+
max_odd, min_even = 0, float('inf')
8+
for value in freq.values():
9+
if value & 1:
10+
max_odd = max(max_odd, value)
11+
else:
12+
min_even = min(min_even, value)
13+
return max_odd - min_even
14+
15+
16+
def main():
17+
s = 'aaaaabbc'
18+
assert Solution().maxDifference(s) == 3
19+
20+
s = 'abcabcab'
21+
assert Solution().maxDifference(s) == 1
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-06-June-LeetCoding-Challenge/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
| June 06 | [2434. Using a Robot to Print the Lexicographically Smallest String](https://leetcode.com/problems/using-a-robot-to-print-the-lexicographically-smallest-string/) | Medium | Unsolved |
1313
| June 07 | [3170. Lexicographically Minimum String After Removing Stars](https://leetcode.com/problems/lexicographically-minimum-string-after-removing-stars/) | Medium | Solved |
1414
| June 08 | [386. Lexicographical Numbers](https://leetcode.com/problems/lexicographical-numbers/) | Medium | Solved |
15-
| June 09 | []() | | |
16-
| June 10 | []() | | |
15+
| June 09 | [440. K-th Smallest in Lexicographical Order](https://leetcode.com/problems/k-th-smallest-in-lexicographical-order/) | Hard | Unsolved |
16+
| June 10 | [3442. Maximum Difference Between Even and Odd Frequency I](https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/) | Easy | Solved |
1717
| June 11 | []() | | |
1818
| June 12 | []() | | |
1919
| June 13 | []() | | |
@@ -39,6 +39,6 @@
3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 0 | 0 | 0 |
42+
| Easy | 1 | 1 | 0 |
4343
| Medium | 6 | 3 | 3 |
44-
| Hard | 2 | 2 | 0 |
44+
| Hard | 3 | 2 | 1 |

0 commit comments

Comments
 (0)