All problems
0791EasyHash TableStringSliding WindowCounting

Three Clean Pigment Windows

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1876Substrings of Size Three with Distinct Characters

This 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.

Examples

Example 1

Input
batch = "kltklm"
Output
4

The windows are `klt`, `ltk`, `tkl` and `klm`. Each one uses three different pigments, so all four are clean.

Example 2

Input
batch = "nnpq"
Output
1

The windows are `nnp`, which repeats pigment `n`, and `npq`, whose three pigments differ, so one window is clean.

Example 3

Input
batch = "rsr"
Output
0

The log holds a single window, `rsr`, and its first and third batches both used pigment `r`.

Constraints

  • 1 <= batch.length <= 100
  • Every character of batch is a lowercase English letter.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_clean_windows(batch: str) -> int:
Java
public int countCleanWindows(String batch)
September 7
Apply