Trains the technique from
LeetCode 1876Substrings of Size Three with Distinct CharactersThis 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 paint line mixes one batch at a time and records which pigment each batch used as a lowercase letter. The letters are written down in mixing order, giving the string batch.
The washing crew looks at every window of three consecutive batches. A window is clean when its three batches used three different pigments. Windows starting at different positions are counted separately, even when they use the same three pigments.
Return the number of clean windows in batch.
Example 1
The windows are `klt`, `ltk`, `tkl` and `klm`. Each one uses three different pigments, so all four are clean.
Example 2
The windows are `nnp`, which repeats pigment `n`, and `npq`, whose three pigments differ, so one window is clean.
Example 3
The log holds a single window, `rsr`, and its first and third batches both used pigment `r`.
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 count_clean_windows(batch: str) -> int:public int countCleanWindows(String batch)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.