Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use a segment tree to perform fast point updates and range queries.
We need each segment tree node to store the length of the longest substring of that segment consisting of only 1 repeating character.
We will also have each segment tree node store the leftmost and rightmost character of the segment, the max length of a prefix substring consisting of only 1 repeating character, and the max length of a suffix substring consisting of only 1 repeating character.
Use this information to properly merge the two segment tree nodes together.