Leetcode Problem 2213. Longest Substring of One Repeating Character
2213. Longest Substring of One Repeating Character
Leetcode Solutions
Segment Tree Approach
Build a segment tree where each node contains information about the longest repeating character substring, the leftmost character, the rightmost character, the length of the repeating characters from the start of the segment, and the length of the repeating characters from the end of the segment.
For each query, update the segment tree at the specific index with the new character.
After each update, recalculate the information in the affected nodes up to the root.
The answer to each query is the length of the longest repeating character substring stored in the root after the update.