2213. Longest Substring of One Repeating Character Hard

@problem@discussion
#Array#String#Segment Tree#Ordered Set



1/**
2 * [2213] Longest Substring of One Repeating Character
3 *
4 * 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.
5 * The i^th query updates the character in s at index queryIndices[i] to the character queryCharacters[i].
6 * 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.
7 *  
8 * Example 1:
9 * 
10 * Input: s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3]
11 * Output: [3,3,4]
12 * Explanation: 
13 * - 1^st query updates s = "<u>bbb</u>acc". The longest substring consisting of one repeating character is "bbb" with length 3.
14 * - 2^nd query updates s = "bbb<u>ccc</u>". 
15 *   The longest substring consisting of one repeating character can be "bbb" or "ccc" with length 3.
16 * - 3^rd query updates s = "<u>bbbb</u>cc". The longest substring consisting of one repeating character is "bbbb" with length 4.
17 * Thus, we return [3,3,4].
18 * 
19 * Example 2:
20 * 
21 * Input: s = "abyzz", queryCharacters = "aa", queryIndices = [2,1]
22 * Output: [2,3]
23 * Explanation:
24 * - 1^st query updates s = "aba<u>zz</u>". The longest substring consisting of one repeating character is "zz" with length 2.
25 * - 2^nd query updates s = "<u>aaa</u>zz". The longest substring consisting of one repeating character is "aaa" with length 3.
26 * Thus, we return [2,3].
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	1 <= s.length <= 10^5
32 * 	s consists of lowercase English letters.
33 * 	k == queryCharacters.length == queryIndices.length
34 * 	1 <= k <= 10^5
35 * 	queryCharacters consists of lowercase English letters.
36 * 	0 <= queryIndices[i] < s.length
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/longest-substring-of-one-repeating-character/
42// discuss: https://leetcode.com/problems/longest-substring-of-one-repeating-character/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn longest_repeating(s: String, query_characters: String, query_indices: Vec<i32>) -> Vec<i32> {
48        vec![]
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_2213() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.