Trains the technique from
LeetCode 2213Longest Substring of One Repeating CharacterThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A lighting strip has one cell per character of s, and s[i] is the colour code currently shown by cell i.
A crew then works through k repaint orders. Order t sets cell queryIndices[t] to the colour queryCharacters[t], and the orders are applied one after another, so each order acts on the strip left behind by the previous one. A repaint may set a cell to the colour it already shows.
After each order, the crew records the length of the longest block of consecutive cells that all show the same colour. Return the list of those k recorded lengths, in order.
Example 1
The strip becomes `wwwyyy`, whose longest block is the run of three; then `wwwyyw`, still three; then `wwwwyw`, where the four leading cells share a colour.
Example 2
The first order turns the strip into `kmk`, whose longest same-colour block holds a single cell. The second order restores `kkk`, so the whole strip is one block of three.
Example 3
The single cell is repainted to the colour it already shows, and the strip still holds one block of length 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def longest_repeating(s: str, queryCharacters: str, queryIndices: list[int]) -> list[int]:public int[] longestRepeating(String s, String queryCharacters, int[] queryIndices)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.