Double X Counter

Finding short fragments inside a string is useful in text checks, logs, and simple analyzers. Write a function count_xx that takes a string s and counts how many times the substring xx appears in it. Overlapping matches count too, so xxx contains two such pairs.

Примеры

Ввод
"abcxx"
Вывод
1
Ввод
"xxx"
Вывод
2
Ввод
"xxxx"
Вывод
3

Нужно реализовать

def count_xx(s: str) -> int:

Теги

stringssliding-window
PostgreSQLv16

Qui apparirà il risultato dell'esecuzione del codice

Visible tests
1
Input
"abcxx"
Expected1
2
Input
"xxx"
Expected2
3
Input
"xxxx"
Expected3
4
Input
"abc"
Expected0
5
Input
""
Expected0
6
Input
" "
Expected0
Focus radio
Paused · SomaFM · Fluid