Input: "aaabbbaaaccc"Output: "a"Explanation: The character 'a' has the maximum consecutive repeats(three times) at the beginning of the substring "aaa".
Example 2:
1
2
3
Input: "abcd"Output: "a"Explanation: Each character repeats only once, so the first character 'a'is the result.
To solve this problem, we can iterate through the string and keep track of the current character and its consecutive count. Whenever we encounter a different character, we compare the current count to the maximum count and update if necessary. We continue this process until we have checked all characters in the string.
Here are the steps:
Initialize variables to keep track of the maximum consecutive repeating character and its count.
Use a loop to iterate through the string.
For each character:
If it matches the previous character, increment the current count.
If it does not match, update the maximum count and character if needed, then reset the current count.
After the loop, ensure to update the maximum count and character one last time in case the string ends with the highest repeating character.
Return the character with the maximum consecutive repeats.