Last active
July 26, 2025 17:18
-
-
Save varnie/143cfc1d0cadb8d21ef89a0e17bf3eb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Consecutive characters | |
| The cardinality of a string is the maximum length of a non-empty substring that contains exactly one unique character. | |
| You need to return the cardinality of the string s. | |
| Example 1: | |
| Input: s = "meet" | |
| Output: 2 | |
| Explanation: the substring "ee" of length 2 contains only the character "e". | |
| Example 2: | |
| Input: s = "abbcccddddeeeeedcba" | |
| Output: 5 | |
| Explanation: the substring "eeeee" of length 5 contains only the character "e". | |
| Limitations: | |
| 1 <= s.length <= 500 | |
| s consists of lowercase English letters only. | |
| """ | |
| from collections import Counter | |
| from functools import reduce | |
| class Solution: | |
| def max_power(self, s: str) -> int: | |
| counters_map = Counter(s) | |
| return reduce(max, counters_map.values()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment