You are given a string s and will perform a series of character update operations on it. After each update, you need to find the longest substring consisting of only one repeating character.
More specifically, you receive:
- A 0-indexed string
s - A string
queryCharactersof lengthkcontaining the new characters - An array
queryIndicesof lengthkcontaining the positions to update
For the i-th query, you update s[queryIndices[i]] to queryCharacters[i], then find the length of the longest substring where all characters are identical.
Goal: Return an array where each element represents the longest repeating substring length after each respective query.
Example: If s = "babacc" and you change s[2] to 'b', the string becomes "babbc", and the longest repeating substring is "bb" with length 2.
Input & Output
Visualization
Time & Space Complexity
Each of k queries takes O(log n) time for segment tree operations
Space for segment tree and interval tracking structures
Constraints
- 1 โค s.length โค 105
- s consists of lowercase English letters only
- k == queryCharacters.length == queryIndices.length
- 1 โค k โค 105
- queryCharacters consists of lowercase English letters only
- 0 โค queryIndices[i] < s.length