Count Overlapping Matches
A regular search can miss matches that start inside a previous match. Given a string s and a substring sub, count how many times sub appears in s, including overlapping occurrences. If sub is empty, return 0.
Примеры
Ввод
"aaaa", "aa"Вывод
3Ввод
"abcabc", "abc"Вывод
2Ввод
"aaa", ""Вывод
0Нужно реализовать
def count_overlapping(s: str, sub: str) -> int:
Теги
stringssliding-window
Log in om je inzendingsgeschiedenis te zien
InloggenLog in om de AI-mentor te gebruiken
InloggenVisible tests
1
Input
"aaaa", "aa"Expected
32
Input
"abcabc", "abc"Expected
23
Input
"aaa", ""Expected
04
Input
"abc", "xyz"Expected
05
Input
"aaaaa", "aaa"Expected
36
Input
"Hello, World!", "aaa"Expected
0Focus radio
Paused · SomaFM · Fluid