2213. Longest Substring of One Repeating Character
2213. Longest Substring of One Repeating Character
Description
You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries.
The i^th query updates the character in s at index queryIndices[i] to the character queryCharacters[i].
Return an array lengths of length k where lengths[i] is the length of the longest substring of s consisting of only one repeating character after the i^th query is performed.
Example 1:
1 | Input: s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3] |
Explanation:
- 1^st query updates s = “bb bacc”. The longest substring consisting of one repeating character is “bbb” with length 3.
- 2^nd query updates s = “bbbc cc”.
The longest substring consisting of one repeating character can be “bbb” or “ccc” with length 3. - 3^rd query updates s = “bbbb cc”. The longest substring consisting of one repeating character is “bbbb” with length 4.
Thus, we return [3,3,4].
Example 2:
1 | Input: s = "abyzz", queryCharacters = "aa", queryIndices = [2,1] |
Explanation:
- 1^st query updates s = “abazz”. The longest substring consisting of one repeating character is “zz” with length 2.
- 2^nd query updates s = “aaazz”. The longest substring consisting of one repeating character is “aaa” with length 3.
Thus, we return [2,3].
Constraints:
1 <= s.length <= 10^5sconsists of lowercase English letters.k == queryCharacters.length == queryIndices.length1 <= k <= 10^5queryCharactersconsists of lowercase English letters.0 <= queryIndices[i] < s.length
Hints/Notes
- 2024/11/13
- segment tree
- 0x3F’s solution(checked)
Solution
Language: C++
1 | class Solution { |