Leetcode Problem 2213. Longest Substring of One Repeating Character

2213. Longest Substring of One Repeating Character

Leetcode Solutions

Segment Tree Approach

  1. 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.
  2. For each query, update the segment tree at the specific index with the new character.
  3. After each update, recalculate the information in the affected nodes up to the root.
  4. The answer to each query is the length of the longest repeating character substring stored in the root after the update.
UML Thumbnail

Maintaining Intervals in Ordered Set/Map

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...