Substrings of Size Three with Distinct Characters
Real-world version: Three Clean Pigment WindowsThe 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.
def count_clean_windows(batch: str) -> int:public int countCleanWindows(String batch)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- First Unique Character in a StringReal-world version: First Solo StopEasy
- Ransom NoteReal-world version: Spell It With TilesEasy
- Maximum Length Substring With Two OccurrencesReal-world version: Longest Twice-Only StretchEasy
- Maximum Number of BalloonsReal-world version: Kettle Signs from the Tile TrayEasy