Distinct Three-Letter Windows
Think of this as a small window moving across the string and checking three neighboring characters at a time. Write a function count_good_substrings that counts substrings of length 3 where all characters are different. Return the number of good substrings. If the same good substring appears in different positions, count each occurrence separately.
Примеры
Ввод
"xyzzaz"Вывод
1Ввод
"aababcabc"Вывод
4Ввод
"abc"Вывод
1Нужно реализовать
def count_good_substrings(s: str) -> int:
Теги
stringssliding-windowset
Log ind for at se indsendelseshistorik
Log indLog ind for at bruge AI-mentor
Log indVisible tests
1
Input
"xyzzaz"Expected
12
Input
"aababcabc"Expected
43
Input
"abc"Expected
14
Input
"aaa"Expected
05
Input
"ab"Expected
06
Input
"abcdef"Expected
4Focus radio
Paused · SomaFM · Fluid