Skip to content

Commit 9c8b4ce

Browse files
add 3541
1 parent f91f8be commit 9c8b4ce

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

  • paginated_contents/algorithms/4th_thousand
  • src/main/java/com/fishercoder/solutions/fourththousand

‎paginated_contents/algorithms/4th_thousand/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
| 3569 | [Count Islands With Total Value Divisible by K](https://leetcode.com/problems/count-islands-with-total-value-divisible-by-k/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3569.java) | | Medium | Union Find
8181
| 3550 | [Smallest Index With Digit Sum Equal to Index](https://leetcode.com/problems/smallest-index-with-digit-sum-equal-to-index/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3550.java) | | Easy |
8282
| 3545 | [Minimum Deletions for At Most K Distinct Characters](https://leetcode.com/problems/minimum-deletions-for-at-most-k-distinct-characters/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3545.java) | | Easy |
83+
| 3541 | [Find Most Frequent Vowel and Consonant](https://leetcode.com/problems/find-most-frequent-vowel-and-consonant/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3541.java) | | Easy |
8384
| 3516 | [Find Closest Person](https://leetcode.com/problems/find-closest-person/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3516.java) | | Easy |
8485
| 3507 | [Minimum Pair Removal to Sort Array I](https://leetcode.com/problems/minimum-pair-removal-to-sort-array-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3507.java) | | Easy |
8586
| 3502 | [Minimum Cost to Reach Every Position](https://leetcode.com/problems/minimum-cost-to-reach-every-position/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3502.java) | | Easy |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.*;
4+
5+
public class _3541 {
6+
public static class Solution1 {
7+
public int maxFreqSum(String s) {
8+
Set<Character> set = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
9+
Map<Character, Integer> vowelMap = new HashMap<>();
10+
Map<Character, Integer> consonantMap = new HashMap<>();
11+
for (char c : s.toCharArray()) {
12+
if (set.contains(c)) {
13+
vowelMap.put(c, vowelMap.getOrDefault(c, 0) + 1);
14+
} else {
15+
consonantMap.put(c, consonantMap.getOrDefault(c, 0) + 1);
16+
}
17+
}
18+
int maxV = 0;
19+
for (Map.Entry<Character, Integer> entry : vowelMap.entrySet()) {
20+
maxV = Math.max(maxV, entry.getValue());
21+
}
22+
int maxCon = 0;
23+
for (Map.Entry<Character, Integer> entry : consonantMap.entrySet()) {
24+
maxCon = Math.max(maxCon, entry.getValue());
25+
}
26+
return maxV + maxCon;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)