Substrings of Size Three with Distinct Characters

A string is **good** if it has no repeated characters. Given a string `s`, return the number of **good substrings of length three** in `s`. If the same substring appears more than once, count every occurrence. A **substring** is a contiguous sequence of characters in a string.

30:00

Substrings of Size Three with Distinct Characters
easy
Free written solution
Topics
Companies

A string is good if it has no repeated characters.

Given a string s, return the number of good substrings of length three in s.

If the same substring appears more than once, count every occurrence.

A substring is a contiguous sequence of characters in a string.

Example 1:
Input: {"s":"xyzzaz"}
Output: 1
Constraints:
  • 1≤s.length≤1001 \leq \text{s.length} \leq 100

  • s consists of lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"xyzzaz"}

Slide a lens three characters wide across "xyzzaz". A window is good when all three pairs differ: a vs b, b vs c, and a vs c.

s, lens of 3

x

0

y

1

z

2

z

3

a

4

z

5

three pair checks

a,bb,ca,c·a·b·c

waiting

count = 0

Variables
VariableValue
count0
DepthFunction Call
Stack empty
0/9