Show problems as
Classic problem #1876EasyHash TableStringSliding WindowCounting

Substrings of Size Three with Distinct Characters

Real-world version: Three Clean Pigment Windows
Tracked in this browser only
Read Substrings of Size Three with Distinct Characters on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

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