Think of a string as a sequence of characters where certain letters might repeat consecutively, like in "aaabbc". The power of a string is defined as the maximum length of any consecutive sequence of identical characters.
For example, in the string "leetcode", the letter 'e' appears consecutively twice, giving it a power of 2. In "abbcccddddeeeeedcba", the letter 'e' appears 5 times in a row, making the power 5.
Your task: Given a string s, find and return its power - the length of the longest substring containing only one unique repeating character.
Input & Output
Visualization
Time & Space Complexity
Single pass through the string of length n, checking each character exactly once
Only using a constant amount of extra space for counters
Constraints
- 1 โค s.length โค 105
- s consists of only lowercase English letters
- The string is non-empty