#2213
Longest Substring of One Repeating Character
master · 1885 · lc hard +32 · verified · 34.2% accepted · 322 likes · top 12%
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 integer array queryIndices of length k, which together describe k queries.
The ith query replaces the character at index queryIndices[i] in s with queryCharacters[i].
After each query, return the length of the longest substring of s consisting of a single repeated character. Return these lengths as an array lengths of size k.
Example 1:
Input: s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3]
Output: [3,3,4]
Explanation:
- 1st query updates s = "bbbacc". The longest substring consisting of one repeating character is "bbb" with length 3.
- 2nd query updates s = "bbbccc".
The longest substring consisting of one repeating character can be "bbb" or "ccc" with length 3.
- 3rd query updates s = "bbbbcc". The longest substring consisting of one repeating character is "bbbb" with length 4.
Thus, we return [3,3,4].
Example 2:
Input: s = "abyzz", queryCharacters = "aa", queryIndices = [2,1]
Output: [2,3]
Explanation:
- 1st query updates s = "abazz". The longest substring consisting of one repeating character is "zz" with length 2.
- 2nd query updates s = "aaazz". The longest substring consisting of one repeating character is "aaa" with length 3.
Thus, we return [2,3].
Code
1
2
3