Skip to content

Commit 61cf7ec

Browse files
Create README.md
1 parent 48d811d commit 61cf7ec

File tree

1 file changed

+59
-0
lines changed
  • Eassy/3442. Maximum Difference Between Even and Odd Frequency I

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# LeetCode Problem: 3442. Maximum Difference Between Even and Odd Frequency I
2+
3+
## 🧠 Problem Statement
4+
5+
You are given a string `s` consisting of lowercase English letters.
6+
Your task is to find the **maximum difference** `diff = a1 - a2` between the frequency of characters `a1` and `a2` such that:
7+
8+
- `a1` has an **odd frequency** in the string.
9+
- `a2` has an **even frequency** in the string.
10+
11+
Return this **maximum difference**.
12+
13+
---
14+
15+
### ✅ Constraints:
16+
17+
- `3 <= s.length <= 100`
18+
- `s` consists only of lowercase English letters.
19+
- `s` contains **at least one character with an odd frequency** and **one with an even frequency**.
20+
21+
---
22+
23+
## 💡 Examples
24+
25+
### Example 1:
26+
27+
### Input:
28+
```python
29+
s = "aaaaabbc"
30+
```
31+
### Output:
32+
```
33+
3
34+
```
35+
### Explanation:
36+
37+
+ `'a'` appears 5 times (odd)
38+
39+
+ `'b'` appears 2 times (even)
40+
41+
+ Maximum difference = 5 - 2 = 3
42+
43+
---
44+
45+
## 🧮 Solution Overview
46+
47+
1. Count the frequency of each character using `collections.Counter`.
48+
2. Filter out frequencies that are **odd** and **even**.
49+
3. Return the difference between:
50+
- The **maximum** odd frequency
51+
- The **minimum** even frequency
52+
53+
---
54+
### ✨ Credit
55+
Prepared by: Muawiya (Coding Moves)
56+
Project Type: LeetCode Problem Solution
57+
Language: Python
58+
59+
---

0 commit comments

Comments
 (0)