Count Good Substrings
EasyStringSliding WindowHash TableMath
Description
A string is good if there are no repeated characters. Given a lowercase string s, return the number of good substrings of length exactly three. A substring is a contiguous sequence of characters in the string. Substrings that occur at different positions are counted separately.
Examples
Input:
s = "xyzzaz"Output:
1Explanation:
Length-3 substrings: 'xyz', 'yzz', 'zza', 'zaz'. Only 'xyz' has no repeats.
Input:
s = "aababcabc"Output:
4Explanation:
Good substrings: 'abc' (twice), 'bca', 'cab'.
Input:
s = "abc"Output:
1Explanation:
Single length-3 substring 'abc' has no repeats.
Input:
s = "aaa"Output:
0Explanation:
Only substring 'aaa' has repeated characters.
Constraints
- •
1 ≤ s.length ≤ 100 - •
s consists of lowercase English letters.