Skip to content
Prev Previous commit
Next Next commit
fix smells
  • Loading branch information
ThanhNIT committed Jun 12, 2022
commit 5a469606cb9a4d43d6f68194e4b99b92ad3ccdf0
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public int[] longestRepeating(String s, String queryCharacters, int[] queryIndic

for (int i = 0; i < qChar.length; i++) {
updateTree(root, queryIndices[i], qChar[i]);
assert root != null;
result[i] = root.max;
}
return result;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
2213\. Longest Substring of One Repeating Character

Hard

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 <code>i<sup>th</sup></code> 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_ <code>i<sup>th</sup></code> _query_ _is performed._

**Example 1:**

**Input:** s = "babacc", queryCharacters = "bcb", queryIndices = [1,3,3]

**Output:** [3,3,4]

**Explanation:** - 1<sup>st</sup> query updates s = "b**b**bacc". The longest substring consisting of one repeating character is "bbb" with length 3.

- 2<sup>nd</sup> query updates s = "bbb**c**cc". The longest substring consisting of one repeating character can be "bbb" or "ccc" with length 3.

- 3<sup>rd</sup> query updates s = "bbb**b**cc". 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:** - 1<sup>st</sup> query updates s = "ab**a**zz". The longest substring consisting of one repeating character is "zz" with length 2.

- 2<sup>nd</sup> query updates s = "a**a**azz". The longest substring consisting of one repeating character is "aaa" with length 3.

Thus, we return [2,3].

**Constraints:**

* <code>1 <= s.length <= 10<sup>5</sup></code>
* `s` consists of lowercase English letters.
* `k == queryCharacters.length == queryIndices.length`
* <code>1 <= k <= 10<sup>5</sup></code>
* `queryCharacters` consists of lowercase English letters.
* `0 <= queryIndices[i] < s.length`
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public class Solution {
public int minDeletion(int[] nums) {
int offset = 0;
int res = 0;
for (int i = 0; i < nums.length; ) {
int i = 0;
while (i < nums.length) {
int j = i;
while (j < nums.length - 1 && nums[j + 1] == nums[j] && (j - offset) % 2 == 0) {
offset++;
Expand Down